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
Problem Description
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!".
Input
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).
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).
Output
If the information correspond to a valid situation,output the number of people,otherwise output"Impossible!".
Sample Input
1 3 2 1 1
Sample Output
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; }