1148 - Mad Counting
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

题意:现在要求一个村庄的总人数,向n个人询问在他们的村庄有多少人和他自己喜欢同一个球队根据数据估计村庄的最少人数

题解:输入数据对数据从小到大排序,如果有连续相同的数a则将这些连续相同的看做是喜欢的同一个球队的人,(相同的个数最多是a+1  如果超过这个则按另一支队算)

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 1000
#define MAXM 1001000
#define INF 0x7fffff
#define LL long long
using namespace std;
int s[MAXM];
int main()
{
int n,m,j,i,t,k;
int sum;
//LL sum;
scanf("%d",&t);
k=1;
while(t--)
{
sum=0;
int ans;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n);
for(i=0;i<n;i++)
{
int num=0;
ans=s[i];
num=s[i];
while(s[i+1]==ans&&num)
{
i=i+1;
num--;
}
sum=sum+ans+1;
}
printf("Case %d: ",k++);
printf("%d\n",sum);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 1000
#define MAXM 1001000
#define INF 0x7fffff
#define LL long long
using namespace std;
int s[MAXM];
int main()
{
int n,m,j,i,t,k;
int sum;
//LL sum;
scanf("%d",&t);
k=1;
while(t--)
{
sum=0;
int ans;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n);
for(i=0;i<n;i++)
{
int num=0;
ans=s[i];
num=s[i];
while(s[i+1]==ans&&num)
{
i=i+1;
num--;
}
sum=sum+ans+1;
}
printf("Case %d: ",k++);
printf("%d\n",sum);
}
return 0;
}

  

light oj 1148 - Mad Counting的更多相关文章

  1. 1148 - Mad Counting(数学)

    1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...

  2. lightoj 1148 Mad Counting(数学水题)

    lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...

  3. LightOJ - 1148 - Mad Counting

    先上题目: 1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...

  4. Light OJ - 1058 Parallelogram Counting(判定平行四边形)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  5. Light OJ 1148

    题意: 给你N 个人, 每个人说出有多少人和他一队, 不包括他自己, 输出总人数最少值 思路: 排个序, 按照给的数目把人分为一组,就可以得出最少人数 #include<bits/stdc++. ...

  6. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  7. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  8. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  9. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

随机推荐

  1. 转载 -- iOS数据持久化存储

    作者:@翁呀伟呀 授权本站转载 概论 所谓的持久化,就是将数据保存到硬盘中,使得在应用程序或机器重启后可以继续访问之前保存的数据.在iOS开发中,有很多数据持久化的方案,接下来我将尝试着介绍一下5种方 ...

  2. OpenStack项目列表

    这个也是必须要熟悉的哟. ~~~~~~~~~~ OpenStack是一个美国国家航空航天局和Rackspace合作研发的,以Apache许可证授权,并且是一个自由软件和开放源代码项目.OpenStac ...

  3. 一些有用的webservice

    http://developer.51cto.com/art/200908/147125.htm 下面总结了一些常用的Web Service,是平时乱逛时收集的,希望对大家有用. ========== ...

  4. SpeedPHP多入口设置 前台和后台入口分开

    因为前台和后台的一些配置是相同的,因此在这里抽取出了共同配置,放到了config.php文件中: config.php <?php // 定义当前目录 define("APP_PATH ...

  5. AVPicture、AVFrame和AVPacket

    http://blog.csdn.net/ym012/article/details/6540065 从定义上可知,AVPicture是AVFrame的一个子集,他们都是数据流在编解过程中用来保存数据 ...

  6. 如何忽略usb host 模式设备连接确认对话框

    <li class="alt"><span><span>package android.hardware.usb;  </span> ...

  7. jstring 和char 之间的转换方法

    //jstring to char* char* jstringTostring(JNIEnv* env, jstring jstr) { char* rtn = NULL; jclass clsst ...

  8. MySQL锁机制

    一.概况MySQL的锁机制比较简单,其最显著的特点是不同的存储引擎支持不同的锁机制.比如,MyISAM和MEMORY存储引擎采用的是表级锁(table-level locking):BDB存储引擎采用 ...

  9. Java问题汇集(1)

    1.javax.el.PropertyNotFoundException: Property 'Price' not found on type pet.petshop.dto.WareDto 简答: ...

  10. 用PowerShell批量收回wsp包

    转:http://www.xuebuyuan.com/168334.html 提供wsp部署的参数:$wspnames:路径下的所有wsp文件名用逗号隔开,如"sumhtestwsp.wsp ...