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 ...
随机推荐
- windows下安装MySQL-python遇到的问题
执行安装命令 pip install MySQL-python 一.执行时会报一个错误 error: Microsoft Visual C++ 9.0 is required (Unable to f ...
- hdu1814Peaceful Commission(2-SAT)
Peaceful Commission Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- [Swift通天遁地]九、拔剑吧-(8)创建气泡式页面切换效果
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Akka源码分析-Actor&ActorContext&ActorRef&ActorCell
分析源码的过程中我们发现,Akka出现了Actor.ActorRef.ActorCell.ActorContext等几个相似的概念,它们之间究竟有什么区别和联系呢? /** * Actor base ...
- $P2299 Mzc和体委的争夺战$
\(problem\) #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef long lon ...
- Laravel5.1学习笔记20 EloquentORM 关系
Eloquent: Relationships Introduction Defining Relationships One To One One To Many Many To Many Has ...
- 【转】Java 集合系列01之 总体框架
Java集合是java提供的工具包,包含了常用的数据结构:集合.链表.队列.栈.数组.映射等.Java集合工具包位置是java.util.*Java集合主要可以划分为4个部分:List列表.Set集合 ...
- Echarts 出现不明竖线解决方案
Echarts出现了不明竖线,百思不得其解.去查相应的解决方案也没有找到. 后来自己点来点去,突然感觉像是上一个Echarts遗留的. 然后去Echarts官网看到了 clear()方法,这个方法可以 ...
- Caffe2:段错误(核心 已转储)
测试Caffe的时候, cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && ech ...
- ECharts实例开发学习笔记二——时间轴
记录一下ECharts时间轴的使用,首先是照着官方的示例做一遍,在这里不要忘了引入timelineOption.js,后面介绍如何动态创建时间轴的记录数,即根据需求可伸缩显示有多少天或者年月等轴标记数 ...