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 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
随机推荐
- CODEVS 1067 机器翻译
题目描述 Description 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义 来替换.对于每个英 ...
- 数据结构---顺序表(C++)
顺序表 是用一段地址连续的存储单元依次存储线性表的数据元素. 通常用一维数组来实现 基本操作: 初始化 销毁 求长 按位查找 按值查找 插入元素 删除位置i的元素 判空操作 遍历操作 示例代码: // ...
- 解决Linux/aix 下的websphere log4j不生效
websphere 解决Linux/aix下的log4j不生效 在目录: /IBM/WebSphere/AppServer/profiles/AppSrv01/properties 增加一个文件:可以 ...
- 浏览器九宫格的简单实现 - 蒋宇捷的专栏 - 博客频道 - CSDN.NET
CSS3 来源:http://blog.csdn.net/hfahe/article/details/6125890#1536434-hi-1-22083-42d97150898b1af15ddaae ...
- eclipse, Log4j配置(真心的详细~)
转自: http://www.cnblogs.com/alipayhutu/archive/2012/06/21/2558249.html a). 新建Java Project>>新建pa ...
- http://f.dataguru.cn/forum.php?mod=viewthread&tid=44212&fromuid=4771
http://f.dataguru.cn/forum.php?mod=viewthread&tid=44212&fromuid=4771
- RxJava学习(一)
注意:文字和图片转载自抛物线博客 参考:http://gank.io/post/560e15be2dca930e00da1083 RxJava 到底是什么 一个词:异步. RxJava 在 GitHu ...
- make menuconfig出错
make[1]: *** [scripts/kconfig/mconf] Error 1 make: *** [menuconfig] Error 2 fixed: sudo apt-get inst ...
- file_operations结构2
对与应用层的每个系统调用,驱动程序都有一个与之对应的函数.对于字符设备驱动程序,这些函数集合在一个file_operations类型的数据结构中,该结构体在Linux内核的include/linux/ ...
- 关于mIdleHandlers 空闲消息
模拟情况说明 创建一个handler对象 该handler持有的是主线程 1.先发送一个延时20秒的message what=35;2.紧接着又发送一个延时10秒的Runnable3.在该Runnab ...