zoukankan      html  css  js  c++  java
  • Light oj 1148

    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 <map>
    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <iostream>
    #include <stack>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <cstdlib>
    //#include <bits/stdc++.h>
    //#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
    ", ++Kcase, ans);
        }
        return 0;
    }
     


  • 相关阅读:
    JVMTIAgent
    Java 虚拟机编程接口JVMIT
    Java调试平台体系JPDA
    什么是缓存
    2019第49周日
    什么是你拥有的资本
    java里的static/final含义
    Java语言和JVM的使用说明书
    画图前端:mermaid。时序图/类图/甘特图/流程图/状态图/饼图。类似工具:Typora
    java通过下划线数字字面量增加可读性:10_00_00表示100000
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770794.html
Copyright © 2011-2022 走看看