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 }
  • 相关阅读:
    爱链笔记-openid获取
    爱链笔记-后端设置环境变量
    爱链笔记-以太坊连接
    爱链笔记-linux操作
    爱链笔记-git
    爱链笔记-后台文件上传
    Dynamics CRM 安全模型的性能问题
    Dynamics 365 登录后网页显示空白
    记D365开发的最佳实践
    Dynamics 365 incident原生实体特点
  • 原文地址:https://www.cnblogs.com/homura/p/4907544.html
Copyright © 2011-2022 走看看