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 |
Test instructions: Now requires the total number of people in a village, to ask n individuals how many in their village and who he likes the same team the minimum number of villages is estimated based on data
Puzzle: Input data to the data from small to large, if there are consecutive same number A will be these consecutive same as the likes of the same team of people, (the same number is a+1 if more than this will be counted by another detachment)
#include <stdio.h> #include <string.h> #include <algorithm> #define MAX 1000#define MAXM 1001000# Define INF 0x7fffff#define LL long Long using namespace Std;int s[maxm];int main () {int n,m,j,i,t,k;int sum;//ll sum;scanf ( "%d", &t), K=1;while (t--) {Sum=0;int ans;scanf ("%d", &n), for (i=0;i<n;i++) scanf ("%d", &s[i]); Sort (s,s+ n); for (i=0;i<n;i++) {int num=0; Ans=s[i];num=s[i];while (s[i+1]==ans&&num) {i=i+1;num--;} sum=sum+ans+1;} printf ("Case%d:", k++);p rintf ("%d\n", sum);} return 0;} #include <stdio.h> #include <string.h> #include <algorithm> #define MAX 1000#define MAXM 1001000# Define INF 0x7fffff#define LL long Long using namespace Std;int s[maxm];int main () {int n,m,j,i,t,k;int sum;//ll sum;scanf ( "%d", &t), K=1;while (t--) {Sum=0;int ans;scanf ("%d", &n), for (i=0;i<n;i++) scanf ("%d", &s[i]); Sort (s,s+ n); for (i=0;i<n;i++) {int num=0; Ans=s[i];num=s[i];while (s[i+1]==ans&&num) {i=i+1;num--;} sum=sum+ans+1;} printf ("Case%d: ", k++);p rintf ("%d\n ", sum);} return 0;}
Light OJ 1148-mad counting