LightOJ - 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个人支持他们支持的球队的村民(除了他自己以外)还有多少人,问村子里面至少有多少人。
不多说,分析一下就可以出结果。
上代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define MAX 1000002
#define ll long long
using namespace std; typedef pair<ll,int> pii; ll s[];
pii p[]; int main()
{
int n,t,x,lo;
ll ans;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
for(int z=;z<=t;z++){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&x);
s[i]=x+;
}
sort(s,s+n);
memset(p,,sizeof(p));
lo=;
p[].first=s[]; p[].second=;
for(int i=;i<n;i++){
if(p[lo].first==s[i]) p[lo].second++;
else{
lo++; p[lo].first=s[i]; p[lo].second=;
}
}
ans=;
for(int i=;i<=lo;i++){
if(p[i].first==p[i].second) ans+=p[i].second;
else if(p[i].first<p[i].second){
ans+=p[i].second/p[i].first*p[i].first;
if(p[i].second%p[i].first!=) ans+=p[i].first;
}else{
ans+=p[i].first;
}
}
printf("Case %d: %lld\n",z,ans);
}
return ;
}
/*1148*/
LightOJ - 1148 - Mad Counting的更多相关文章
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- light oj 1148 - Mad Counting
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...
- 1148 - Mad Counting(数学)
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...
- LightOj 1148 Basic Math
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob ...
- LightOJ 1058 - Parallelogram Counting 几何思维
http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...
- LightOJ - 1058 - Parallelogram Counting(数学,计算几何)
链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by t ...
- LightOj 1170 - Counting Perfect BST (折半枚举 + 卡特兰树)
题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1170 题目描述: 给出一些满足完美性质的一列数(x > 1 and y ...
- LightOJ - 1148-Mad Counting (数学)
链接: https://vjudge.net/problem/LightOJ-1148 题意: Mob was hijacked by the mayor of the Town "Trut ...
- LightOJ - 1170 - Counting Perfect BST(卡特兰数)
链接: https://vjudge.net/problem/LightOJ-1170 题意: BST is the acronym for Binary Search Tree. A BST is ...
随机推荐
- SQL使用IN参量不能超过1000的表现形式以及解决办法
如果出现这个错误说明你传的参量是超过了一千个值:列如,你拼接了1001个id: 如何解决那,我这里提供两种方法: 1.每1000条加一个or in 列: 原:select p.* from t_pre ...
- error: undefined reference to 'property_set (转载)
转自:http://blog.csdn.net/u011589606/article/details/23474241 in the cpp file, please include #include ...
- roundabout旋转幻灯
jquery.roundabout.js文件/** * jQuery Roundabout - v2.4.2 * http://fredhq.com/projects/roundabout * * M ...
- selenium3 + python - iframe
一.frame和iframe区别 Frame与Iframe两者可以实现的功能基本相同,不过Iframe比Frame具有更多的灵活性. frame是整个页面的框架,iframe是内嵌的网页元素,也可以说 ...
- $P5017 摆渡车$
problem 毒瘤\(DP\) #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef lon ...
- Ubuntu 系统的常用快捷键
Ubuntu操作基本快捷键 ibus-setup :设置系统输入法 scp filename username@serverIp:/home/xxx/xxx/filename 回车输入该usern ...
- JVM 优化之逃逸分析
整理自 周志明<深入JVM> 1, 是JVM优化技术,它不是直接优化手段,而是为其它优化手段提供依据. 2,逃逸分析主要就是分析对象的动态作用域. 3,逃逸有两种:方法逃逸和线程逃逸. ...
- 【转】Java 集合系列10之 HashMap详细介绍(源码解析)和使用示例
概要 这一章,我们对HashMap进行学习.我们先对HashMap有个整体认识,然后再学习它的源码,最后再通过实例来学会使用HashMap.内容包括:第1部分 HashMap介绍第2部分 HashMa ...
- Android 根据QQ号跳转到QQ聊天界面
从自己开发的应用中根据QQ号跳转到QQ应用的聊天界面,实现起来很方便: 即: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(" ...
- Java 中访问数据库的步骤?Statement 和PreparedStatement 之间的区别?
Java 中访问数据库的步骤?Statement 和PreparedStatement 之间的区别? Java 中访问数据库的步骤 1)注册驱动: 2)建立连接: 3)创建Statement: 4)执 ...