您的位置:首页 > 其它

HDU 2690 Boys and girls

2015-08-21 23:08 218 查看

Boys and girls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 901    Accepted Submission(s): 248


[align=left]Problem Description[/align]
In a big party,there are N people some are boys and the others are girls.Now we will ask them how many girls can they see around the party(expect themselves).And the number will be A1,A2,A3...AN.Then can you tell the total number
of girls using the information above?If the information is wrong and doesn't correspond to a unique valid situation,just output"Impossible!".
 

[align=left]Input[/align]
The first line will contain a integer T,then T cases.

At first,there is a integer N,means N people(1<=N<10000),then N integers A1,A2...AN,indicating how many girls he/she sees(except himself/hersels).

 

[align=left]Output[/align]
If the information correspond to a valid situation,output the number of people,otherwise output"Impossible!".
 

[align=left]Sample Input[/align]

1
3
2 1 1

 

[align=left]Sample Output[/align]

2
这是个水题,题意就是,有N个人,其中有男生和女生,给你N组数,是这N个人分别看到的除自己以外的女生人数,要求出有多少女生。
男生看到的是女生总人数,而女生看到的是女生总人数-1。这个题只需要讨论下0和1的时候就行了。
#include <stdio.h>
int main()
{
int n,T;
int i,j,a[10005],max,peace;
scanf("%d",&T);
while(T--)
{
max=-1;
peace=1;		//作为是否符合要求的标志
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",a+i);
if(a[i]>max)
max=a[i];
}
if(n==0 || n==1)
peace=0;

for(i=1;i<=n && peace;i++)
{
if(a[i]!=max && a[i]!=max-1)
peace=0;
}
if(peace)
printf("%d\n",max);
else
printf("Impossible!\n");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: