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; }
相关文章推荐
- 王爽《汇编语言》第2版-----1、基础知识
- 剑指offer 不用加减乘除做加法
- 记录-使用CSDN-markdown编辑器
- HTTP协议简介
- uva 1318 - Monster Trap(bfs+暴力)
- 关于document.write
- 计算几何-经典算法-凸包
- 黑马程序员-JAVA基础之多线程
- android 单点登陆
- TLb和硬件Cache
- 数据结构之---C语言实现最短路径之Floyd(弗洛伊德)算法
- 如何制作 Objective-C 的UML图 [2]
- 宜昌IT软件资源汇总
- Andrew Ng的机器学习视频目录(from coursera, 2014)
- 2.1-apache配置静态缓存
- 【软件设计】六大设计原则讲解
- hdoj-1248【水&&floyd】
- IL中的栈和闪电的Owin推荐
- 文档收藏瘾的治疗配方(实现收集文档科学重复阅读的最佳实践)
- tomcat安全设置