lightoj 1148 - Mad Counting (数学规律&模拟)

1148 - Mad Counting
PDF (English) Statistics Forum
Time Limit: 0.5 second(s) Memory Limit: 32 MB
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
//题意:

要调查城市里有多少人,对n个人进行了调查,每个人都说出与他支持相同的球队的人数,然后让我们根据这些条件判断城市最少有多少人。

#include
#include
#include
using namespace std;
int a[60];
int main()
{	
	int t;
	int T=1;
	int n,i;
	int num,sum;
	scanf("%d",&t);
	while(t--)
	{		
		num=sum=0;
		scanf("%d",&n);
		for(i=0;i


 

#include
#include
#include
using namespace std;
int a[1000010];
int main()
{
	int t,T=1,n,i,x,k;
	int sum;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		memset(a,0,sizeof(a));
		sum=n;
		int mm=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&x);
			a[x]++;
			mm=max(x,mm);
		}
		for(i=1;i<=mm;i++)
		{
			k=a[i]%(i+1);
			if(k!=0)
				sum+=(i+1)-k;
		}
		printf("Case %d: %d\n",T++,sum);
	}
	return 0;
} 


你可能感兴趣的:(模拟,好题,lightoj)