博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Light oj 1148 - Mad Counting【模拟】
阅读量:6361 次
发布时间:2019-06-23

本文共 2161 字,大约阅读时间需要 7 分钟。

  
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

 


PROBLEM SETTER: MUHAMMAD RIFAYAT SAMEE
SPECIAL THANKS: JANE ALAM JAN
题意:
给你一个集合a,第i个数字表示有ai个人和他是一个集合的,问你求出最小的人数。
思路:
进行sort升序排序,如果当前值与上一个的值不同时,这个就是一个新的集合,然后在进行判断有几个样的集合。
#include #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#define LOACL#define space " "using namespace std;typedef long long LL;//typedef __int64 Int;typedef pair
paii;const int INF = 0x3f3f3f3f;const double ESP = 1e-5;const double Pi = acos(-1.0);const int MOD = 1e9+5;const int MAXN = 1e6 + 5;int ar[MAXN];int main() { int t, n; int Kcase = 0; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &ar[i]); } sort(ar, ar + n); int ans = 0, num = 1; int last = INF; for (int i = 0; i < n; i++) { //如果两个不同,或者是两个集合 if (last != ar[i] || !num) { last = ar[i]; ans += ar[i] + 1; num = ar[i]; } else num--; } printf("Case %d: %d\n", ++Kcase, ans); } return 0;}

 

 

 

转载于:https://www.cnblogs.com/cniwoq/p/6770794.html

你可能感兴趣的文章
弹窗查看内容时 内容滚动区域设置为body区
查看>>
Windows Azure Platform Introduction (6) Windows Azure应用程序运行环境
查看>>
Windows Azure VM Role (3) 在VHD中安装Windows Server 2008 R2
查看>>
Windows 8 Platform (三) Windows 8 Developer Preview
查看>>
根据条件用一个表的字段,去更新另一个表的字段
查看>>
thinkphp模板中使用自定义函数
查看>>
TP复习3
查看>>
(Delphi) Using the Disk Cache 使用磁盘缓存
查看>>
用Feature的方式删除SharePoint2010的Page中重复的WebPart
查看>>
递归算法学习系列之三(快速排序)
查看>>
从TdataSet生成OleVariant
查看>>
预告和目录: Wayne Game Solution 0.1 网络游戏大厅 从最基础开始
查看>>
xBIM WeXplorer xViewer的导航,相机、剖切、隐藏 等操作
查看>>
(转)预编译头文件
查看>>
艾伟_转载:浅析IHttpModule和IHttpHandler
查看>>
百万级访问量网站的技术准备工作
查看>>
Gnome Tweak Tool 3.0.5发布
查看>>
杭州鼎家被曝破产:长租公寓过度金融化酿恶果
查看>>
刘慈欣点赞科幻电影《流浪地球》:震撼心灵
查看>>
香港将发展中央儿童数据资料库 研究整合各部门数据
查看>>