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. javascript editor

    http://www.jetbrains.com/webstorm/download/download_thanks.jsp?os=win

  2. maven 添加Sqlserver的jdbc jar包

    maven添加sqlserver的jdbc驱动包 jdbc.jar download url->http://pan.baidu.com/s/1hrEhdti 通过maven命令将jar包安装到 ...

  3. 分别用js和jq实现百度全选反选效果

    js实现过程 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  4. 数据结构———重载与模板(C++)

    相关信息 /* * * @subject 数据结构 * @author 信管1142班 201411671210 JJ lai * * @program 模板与重载 * */ 实验一: /* 要求如下 ...

  5. jquery upgrade

    http://www.ifanybug.com/article/00125 http://zhidao.baidu.com/question/69399476.html http://www.tmtp ...

  6. 保护模式下GDTR,LDTR,全局描述符表,局部描述符表和选择器的关系

    这张图要注意:右边两个0-15,其中上面的是LDTR,  下面的是选择子. 图下第五个标线,是两个线交叉的,实际上第五个线是指向右边水平的那个线. 没有箭头的两组线分别表示GDT的区间,LDT的区间 ...

  7. ANDROID_MARS学习笔记_S01原始版_022_MP3PLAYER002_本地及remote标签

    一.简介 1.在main.xml中用TabHost.TabWidget.FrameLayout标签作布局 2.在MainActivity中生成TabHost.TabSpec,调用setIndicato ...

  8. USB Type-C 应用面临安全性考验,USB-IF 将推动新认证机制

    USB 应用已经达到空前盛况,横跨电脑.移动设备.周边设备.影音器材等范畴,是一个极为普遍常见的界面.进入 USB Type-C 世代由于一并推动 USB-PD,过去没有严格执行的认证要求,基于安全性 ...

  9. UDP模块(黑胶体)

    UDP模块是采用PIP封装技术的U盘半成品模块,直接加上外壳,就是成品U盘. 它有以下特点: 防水.防尘.防震. 一体WAFER封装技术. 薄.轻.时尚. 产品装配方便.简单. 产品标准化,适合客户在 ...

  10. 坑爹的libxml2 for mingw 编译 (二)

    makefile 中由于大量使用了cmd /C ""样式去执行mkdir和copy操作,导致mingw最后出错,因为会从mingw切换至cmd界面.因此需要把相关代码进行修改. # ...