0
点赞
收藏
分享

微信扫一扫

LIGHTOJ-1148 - Mad Counting (规律)

菜菜捞捞 2023-02-07 阅读 20


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 Npeople 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
 

题意:

一个村有一些人,询问n个人,每个人回答有几个人与他喜欢同一球队;

最后问满足上述的情况下,问该村最少有多少人?

分析:

我们知道相同数字的是要分成一组的,多大一组是最好的呢?

假如数字为n,则n+1个n最好。

原因最好的情况就是只有采访的这些人,也就是说他回答有n个人,则最好还有n个人跟他回答一样,所以n+1个n最好。

如果不到呢,假如有2个3,则根据它最好的情况就是这两个3是一样的人,即3+1(1是自身),即n+1

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+5;
int a[100],num[N];

int main(){
int T;
scanf("%d",&T);
int cas=0;
while(T--)
{
LL n;
scanf("%lld",&n);
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
num[a[i]]++;
}
LL ans=0;

for(int i=0;i<N;i++)
{
ans+=num[i]/(i+1)*(i+1);
if(num[i]%(i+1)!=0)
ans+=(i+1);
}
printf("Case %d: %lld\n",++cas,ans);


}
}

 

举报

相关推荐

0 条评论