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

题解:没理解清题意,看见世界杯,就想着中国队和巴西队,然而并没有这么少的队;

其实吧,这个题就是说,问卷调查,问除了你还有几个人和你支持同一个队;本渣的思路是:统计x的相同的个数为y,因为,两个人支持同一个队,人数必然相同,那么让这y个x组最小的队,一个x再要x个人可以组一个队,那么找y里面有几个x+1即可,那么代码救出来了;

代码:

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<map>
 7 #include<vector>
 8 #include<stack>
 9 #include<queue>
10 using namespace std;
11 const int INF=0x3f3f3f3f;
12 const int MAXN=1e6+10;
13 int pre[MAXN];
14 int a[MAXN];
15 int main(){
16     int T,N,temp,flot=0;
17     scanf("%d",&T);
18     while(T--){
19         memset(pre,0,sizeof(pre));
20     scanf("%d",&N);
21     int pos=0;
22     for(int i=0;i<N;i++){
23         scanf("%d",&temp);
24         if(!pre[temp])
25             a[pos++]=temp;
26             pre[temp]++;
27     }
28     int ans=0,x,y;
29     for(int i=0;i<pos;i++){
30         x=a[i];y=pre[a[i]];
31         ans+=y/(x+1)*(x+1);
32         if(y%(x+1)!=0)ans+=x+1;
33     }
34     printf("Case %d: %d\n",++flot,ans);
35     }
36     return 0;
37 }
时间: 2024-10-10 14:59:03

1148 - Mad Counting(数学)的相关文章

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

light oj 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 p

LightOJ - 1148 Mad Counting(坑)

Mad Counting Time Limit: 500MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status 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 a

17997 Simple Counting 数学

17997 Simple Counting 时间限制:2000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: 不限定 Description Ly is crazy about counting . Recently , he got a simple problem , but he had to learn Gaoshu these days .So , he turns to you for help . You are given a sequenc

Codeforces 911D. Inversion Counting (数学、思维)

题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对.于是,对于一个数列a[1..n],给定m次操作.对于每一次操作,给定l,r(1≤l<r≤n),将序列a[l..r]倒置.求倒置后的逆序对的数量的奇偶性. 题解: 假设现在我们有一个序列并翻转这个序列[l,r]区间里面的数.假设某个数的k值是指在这个值后面小于这个数的数的个数,其实我们可以发现对于[1,l

UVA 11401 - Triangle CountingTriangle Counting 数学

You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. Howmany distinct triangles can you make? Note that, two triangles will be considered di?erent if they haveat least 1 pair of arms with di?erent length

Light OJ 1148

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

LightOj 1148 Basic Math

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 pro

lightoj Basic Math 数论基础

这里是除去Beginners Problems后的部分 1020 - A Childhood Game 巴什博奕(Bash Game) #include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n; char s[10]; scanf("%d",&t); while(t--) { scanf("%d%s",&n,&s); prin