light oj 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的更多相关文章
- 1148 - Mad Counting(数学)
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- LightOJ - 1148 - Mad Counting
先上题目: 1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...
- Light OJ - 1058 Parallelogram Counting(判定平行四边形)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- Light OJ 1148
题意: 给你N 个人, 每个人说出有多少人和他一队, 不包括他自己, 输出总人数最少值 思路: 排个序, 按照给的数目把人分为一组,就可以得出最少人数 #include<bits/stdc++. ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
随机推荐
- ios coredata 老代码备用参考
iPhone OS在2009年6月份推出3.0版本SDK,其中一个特性是引入了Mac SDK中的core data.是一种ORM(Object Relationships Mapping)解决方案,类 ...
- Junit4.12、Hamcrest1.3、Eclemma的安装和使用
1. Junit4.12和Hamcrest1.3的安装过程 步骤: 网上下载Junit和Hamcrest包文件,保存在本地. 新建Java项目命名为Triangle,在Eclipse菜单栏选择项目(P ...
- 关于移动端和PC端的交互的区别
对于现在的移动端设备的普及,移动端上的用户体验成了一个重要的关注点. 看了一些网上的关于移动端的交互和用户体验的知识,这里总结了一些.若有不足的地方,希望大家能够积极补充. PC端和移动端的产品的设计 ...
- c++ 联合体
联合体分配的内存大小是成员变量中最大变量的大小 联合体的成员变量共享内存 小段模式(X86就是) 低位数据存在低地址单元 大端模式 高位字节存在低地址单元
- XSS脚本攻击漫谈
XSS跨站脚本攻击一直都被认为是客户端 Web安全中最主流的攻击方式.因为 Web环境的复杂性以及 XSS跨站脚本攻击的多变性,使得该类型攻击很难彻底解决.那么,XSS跨站脚本攻击具体攻击行为是什 ...
- java static 变量,和方法从属于类
第36集 java static 变量,和方法从属于类 可以用类来直接调用static属性和方法 static方法不能调用非静态的属性和方法,反之可以 new产生的对象,不包括static 属性和方法
- 在Android手机上安装linux系统
在anroid手机中安装fedora系统.记住不只是教你安装fedora系统. 需要的备注与软件 1.一个已经root的Android手机,记住是root后的,root后的,root后的.(重要的事情 ...
- MMU、Icache、Dcache
http://blog.csdn.net/iodoo/article/details/8954014 i-cache(instruction cache)是指令高速缓冲存储器. Cache存储体:存放 ...
- Android RelativeLayout
RelativeLayout为相对布局,这种布局内的组件总是相对兄弟组件.父容器来确定的,在定义控件的位置时,需要参照其他控件的位置. 这个程序实现了一个梅花的相对布局 <?xml versio ...
- Yii CDbCriteria
Yii的Active Recorder包装了很多. 特别是把SQL中 把where,order,limit,IN/not IN,like等常用短句都包含进CDbCriteria这个类中去,这样整个代码 ...