Light oj--1148
来源:互联网 发布:斗战胜佛工艺品知乎 编辑:程序博客网 时间:2024/06/03 21:56
Description
Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to this problem will be counting people one by one. But as we all know Mob is a bit lazy, so he is finding some other approach so that the time will be minimized. Suddenly he found a poll result of that town where N people were asked "How many people in this town other than yourself support the same team as you in the FIFA world CUP 2010?" Now Mob wants to know if he can find the minimum possible population of the town from this statistics. Note that no people were asked the question more than once.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with an integer N (1 ≤ N ≤ 50). The next line will contain N integers denoting the replies (0 to 106) of the people.
Output
For each case, print the case number and the minimum possible population of the town.
Sample Input
2
4
1 1 2 2
1
0
Sample Output
Case 1: 5
Case 2: 1
解题思路:主要理解这一句话,How many people in this town other than yourself support the same team as you in the FIFA world CUP 2010?",这个村子里除你之外,还有几个人和你支持同样的队伍,表示我对这句话理解错了,WA了好几遍。
代码如下:
#include<stdio.h>#include<string.h>int a[1000010];int main(){ int t,n,sum,m,k,max; k=1; scanf("%d",&t);while(t--){max=0; memset(a,0,sizeof(a));sum=0;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&m);if(m>max)max=m; a[m]++;}for(int i=0;i<=max;i++){sum+=a[i]/(i+1)*(i+1);if(a[i]%(i+1)!=0)sum+=i+1;}printf("Case %d: %d\n",k++,sum);}return 0;}
- Light oj--1148
- Light OJ 1148
- light oj 1148 - Mad Counting
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1148 - Mad Counting【规律】
- light oj 1148 - Mad Counting 【思维】
- Light oj 1148 - Mad Counting【模拟】
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- light oj 1128
- Light OJ 1055 BFS
- 一个编译静态库的make脚本
- LightOJ 1348 Aladdin and the Return Journey(树链剖分+线段树)
- Java网络编程示例
- 黑马程序员——OC学习——Protocol和代理设计模式
- fzoj Problem 2188 过河I 【BFS】
- Light oj--1148
- 九度OJ 1358:陈博的平均主义 (遍历、递归)
- Android Studio 无法关联到 svn
- bzoj1082 跨栏 二分&搜索
- 解放思想——规则和道德枷锁
- 【Html】使用表单标签,与用户交互
- 郑大校赛总结
- 3D数学总结
- Android Handler