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 ...
随机推荐
- Maya Calendar
http://poj.org/problem?id=1008 按第一种记录方法算出总天数,然后按第二种记录方式输出. #include<stdio.h> #include<strin ...
- [Swift通天遁地]七、数据与安全-(9)文件的压缩和解压
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- python - 解决 ModuleNotFoundError: No module named 'pip'
1.pip的版本为 9.0.3 想用 pip install -U pip 更新下包,但是在更新过程中出现了报错,如下所示: 2.然后尝试用pip install pandas包,提示 Module ...
- AcWing算法基础1.5
前缀和与差分 两个内容都比较少,就放一起写了 设数组 a 的前 n 项为a1 , a2 , a3 ... an 前缀和数组就是每一项是a数组的前i项和,比如前缀和数组res,res[ 1 ] = a[ ...
- 从flappy bird中论优化
前两天刚刚做完2014年noipD1T3飞扬的小鸟 其实这道题本身并不是一道很难的DP 状态容易想到,转移也容易想到 但是出于我的基础较差,还是出了较大的偏差 Problem: Flappy Bird ...
- Fckeditor使用方法
下载地址 http://ckeditor.com/download <?php require('../fckeditor/fckeditor.php'); ?> <html> ...
- Android基础TOP3_1:纵横屏切换
在Res下建立layout-port文件夹 为竖屏时加载的界面: 建立layout-land 文件夹 为横屏加载的界面
- JS——offset
1.offsetWidth.offsetHeight返回盒子宽度和高度,包括padding与border,不包括margin 2.offsetLeft.offsetTop返回盒子距离定位盒子的x轴方向 ...
- Tcl之Lab1
Task 1. Use help 1) What is the default switch for the redirect command? -file help -v redirect # or ...
- CSS (层叠样式表)
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.CSS不仅可以静态 ...