HDU 2690 Boys and girls

77 篇文章 0 订阅
36 篇文章 1 订阅

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).
 

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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值