zoukankan      html  css  js  c++  java
  • 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, 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

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<map>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int a[55],cnt[55];
    11     int T,n,ans;
    12     map<int,int>mp;
    13     scanf("%d",&T);
    14     for(int kase=1;kase<=T;kase++)
    15     {
    16         mp.clear();
    17         memset(cnt,0,sizeof(cnt));
    18         ans=0;
    19         scanf("%d",&n);
    20         int id=0;
    21         for(int i=0;i<n;i++)
    22         {
    23             scanf("%d",&a[i]);
    24             if(!mp.count(a[i]))
    25                 mp[a[i]]=++id;
    26             cnt[mp[a[i]]]++;
    27         }
    28         for(map<int,int>::iterator iter=mp.begin();iter!=mp.end();iter++)
    29             ans+=ceil(cnt[iter->second]*1.0/(iter->first+1))*(iter->first+1);
    30         printf("Case %d: %d
    ",kase,ans);
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    关于两端对齐
    关于删除节点的兼容写法
    因为一个css,导致网页在手机上滑动不流畅
    Java垃圾回收机制
    Java的ArrayList
    大神说,规则引擎,反正不懂,留个纪念,以后看
    Java克隆
    i++和++i的区别
    JavaScript中的方法或者变量名称前面有下划线,是做什么的?
    RandomAccess接口是空的,那它是用来做什么的呢?
  • 原文地址:https://www.cnblogs.com/homura/p/4907544.html
Copyright © 2011-2022 走看看