• 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 }
  • 相关阅读:
    谷歌浏览器提示Adobe Flash Player因过期而遭到阻止
    Oracle 查看表空间剩余与创建空间语法
    招标
    iphone刷机各种错误
    oracle 创建dblink
    imp-00002 无法打开。。
    oracle 大字段clob检索
    (一)EasyUI 使用——基本概念
    使用 Google 高级搜索的一些技巧
    (四)Maven构建多模块项目
  • 原文地址:https://www.cnblogs.com/homura/p/4907544.html
Copyright © 2020-2023  润新知