1148-mad counting
|
PDF (中文版) |
Statistics |
Forum |
Time limit:0.5 second (s) |
Memory limit:32 MB |
Mob is 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'll be a counting people one by one. But as we all know Mob is a bit-lazy, so he's finding some other approach so, the time would be minimized. Suddenly he found a poll result of that town where N people were asked "how many people in the town other than Y Ourself support the same team as your 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 is starts with an integer N (1≤n≤50). The next line would 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 |
The puzzle: Don't understand Qing test instructions, see the World Cup, think of China and Brazil team, but there are not so few teams;
In fact, the problem is that, the questionnaire, ask except you still have a few people and you support the same team; the idea of this slag is: statistics x the same number is Y, because, two people support the same team, the number must be the same, then let this y x group of the smallest team, an X and then x person can group A team, Then find y inside a few x+1 can, then the code saved out;
Code:
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>Ten using namespacestd; One Const intinf=0x3f3f3f3f; A Const intmaxn=1e6+Ten; - intPRE[MAXN]; - intA[MAXN]; the intMain () { - intt,n,temp,flot=0; -scanf"%d",&T); - while(t--){ +memset (PRE,0,sizeof(pre)); -scanf"%d",&N); + intpos=0; A for(intI=0; i<n;i++){ atscanf"%d",&temp); - if(!Pre[temp]) -a[pos++]=temp; -pre[temp]++; - } - intans=0, x, y; in for(intI=0; i<pos;i++){ -x=a[i];y=Pre[a[i]]; toans+=y/(x+1) * (x+1); + if(Y% (x+1)!=0) ans+=x+1; - } theprintf"Case %d:%d\n",++Flot,ans); * } $ return 0;Panax Notoginseng}
1148-mad Counting (mathematics)