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

 


PROBLEM SETTER: MUHAMMAD RIFAYAT SAMEE
SPECIAL THANKS: JANE ALAM JAN
题意:
给你一个集合a,第i个数字表示有ai个人和他是一个集合的,问你求出最小的人数。
思路:
进行sort升序排序,如果当前值与上一个的值不同时,这个就是一个新的集合,然后在进行判断有几个样的集合。
#include 
#include <set>
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include <string>
#include 
#include 
//#include 
//#define LOACL
#define space " "
using namespace std;
typedef long long LL;
//typedef __int64 Int;
typedef pair<int, int> paii;
const int INF = 0x3f3f3f3f;
const double ESP = 1e-5;
const double Pi = acos(-1.0);
const int MOD = 1e9+5;
const int MAXN = 1e6 + 5;
int ar[MAXN];
int  main() {
    int t, n;
    int Kcase = 0;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%d", &ar[i]);
        }
        sort(ar, ar + n);
        int ans = 0, num = 1;
        int last = INF;
        for (int i = 0; i < n; i++) {
            //如果两个不同,或者是两个集合
            if (last != ar[i] || !num) {
                last = ar[i];
                ans += ar[i] + 1;
                num = ar[i];
            }
            else num--;
        }
        printf("Case %d: %d\n", ++Kcase, ans);
    }
    return 0;
}

 

 


 

转载于:https://www.cnblogs.com/cniwoq/p/6770794.html

你可能感兴趣的:(Light oj 1148 - Mad Counting【模拟】)