首页 > 其他 > 详细

Light OJ 1148

时间:2015-10-24 21:46:15      阅读:368      评论:0      收藏:0      [点我收藏+]

1148 - Mad Counting

 
 

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

Output for Sample Input

2

4

1 1 2 2

1

0

Case 1: 5

Case 2: 1

 

 

 

 

 

 

 

 

 

 

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<map>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int a[55],cnt[55];
11     int T,n,ans;
12     map<int,int>mp;
13     scanf("%d",&T);
14     for(int kase=1;kase<=T;kase++)
15     {
16         mp.clear();
17         memset(cnt,0,sizeof(cnt));
18         ans=0;
19         scanf("%d",&n);
20         int id=0;
21         for(int i=0;i<n;i++)
22         {
23             scanf("%d",&a[i]);
24             if(!mp.count(a[i]))
25                 mp[a[i]]=++id;
26             cnt[mp[a[i]]]++;
27         }
28         for(map<int,int>::iterator iter=mp.begin();iter!=mp.end();iter++)
29             ans+=ceil(cnt[iter->second]*1.0/(iter->first+1))*(iter->first+1);
30         printf("Case %d: %d\n",kase,ans);
31     }
32     return 0;
33 }

 

Light OJ 1148

原文:http://www.cnblogs.com/homura/p/4907544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!