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 |
题解:没理解清题意,看见世界杯,就想着中国队和巴西队,然而并没有这么少的队;
其实吧,这个题就是说,问卷调查,问除了你还有几个人和你支持同一个队;本渣的思路是:统计x的相同的个数为y,因为,两个人支持同一个队,人数必然相同,那么让这y个x组最小的队,一个x再要x个人可以组一个队,那么找y里面有几个x+1即可,那么代码救出来了;
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=1e6+;
int pre[MAXN];
int a[MAXN];
int main(){
int T,N,temp,flot=;
scanf("%d",&T);
while(T--){
memset(pre,,sizeof(pre));
scanf("%d",&N);
int pos=;
for(int i=;i<N;i++){
scanf("%d",&temp);
if(!pre[temp])
a[pos++]=temp;
pre[temp]++;
}
int ans=,x,y;
for(int i=;i<pos;i++){
x=a[i];y=pre[a[i]];
ans+=y/(x+)*(x+);
if(y%(x+)!=)ans+=x+;
}
printf("Case %d: %d\n",++flot,ans);
}
return ;
}
再次出了这个题,代码;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
#define T_T while(T--)
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e6+100;
int m[MAXN];
int main(){
int T,kase=0,N;
SI(T);
T_T{
SI(N);
int x;
for(int i=0;i<N;i++){
SI(x);
m[i]=x+1;
}
sort(m,m+N);
int temp=m[0],flot=1,sum=m[0];
for(int i=1;i<N;i++){
if(m[i]!=m[i-1]){
flot=1;temp=m[i];
sum+=temp;
continue;
}
flot++;
if(flot>temp)sum+=temp,flot=1; }
printf("Case %d: %d\n",++kase,sum);
}
return 0;
}
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 ...
- LightOJ - 1148 - Mad Counting
先上题目: 1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...
- Codeforces 911D. Inversion Counting (数学、思维)
题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...
- 17997 Simple Counting 数学
17997 Simple Counting 时间限制:2000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: 不限定 Description Ly is craz ...
- UVA 11401 - Triangle CountingTriangle Counting 数学
You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. ...
- LightOj 1148 Basic Math
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob ...
- acdream.A Very Easy Triangle Counting Game(数学推导)
A - A Very Easy Triangle Counting Game Time Limit:1000MS Memory Limit:64000KB 64bit IO Forma ...
- UVALive 5058 Counting BST 数学
B - Counting BST Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
随机推荐
- vs2013 中HTML页 无法在设计窗口中查看的解决
VS2013不支持HTML文件的解决办法: 1.将html文件重命名为aspx即可.不需要创建项目,直接拖进vs即可. 2.打开VS菜单->工具->选项->文本编辑器->文件扩 ...
- jQuery 迭代器
在 叶小钗 的博客中看到一段关于遍历的代码 var ajQuery = {}; function dir(elem, dir, until) { var matched = [], truncate ...
- R与数据分析旧笔记(二)随机抽样的一个综合例子
题目:模拟产生统计专业同学的名单(学号区分),记录数学分析.线性代数.概率统计三科成绩,然后进行一些统计分析 > num=seq(10378001,10378100) > num [1] ...
- 《JavaScript+DOM编程艺术》的摘要(二)---DOM中的几个方法
//DOM: //对象是一种独立的数据集合,与某个特定对象相关联的变量被称为这个对象的属性,通过某个特定对象可以为之调用的函数被称为这个对象的方法 // //4个非常实用的DOM方法: //检索特定元 ...
- 解决:sudo: parse error in /etc/sudoers near line 24 ...报错
ubuntu系统下由于添加用户权限的时候直接用的vim对 /etc/sudoers 文件编辑,保存退出的时候,再使用sudo su 等等命令一直报错如下: sudo: parse error in / ...
- 在FL2440上使用kei MDK 调试程序(J-link)
<一>新建一个工程 单击Project ->New µVision Project...菜单项 <二>选择CPU 这里我们选择三星的2440A 点击OK后会提示你是否添加 ...
- HTML5速查表
HTML5速查表 标签 描述 版本 属性 <!--...--> 定义注释 4 / 5 none <!DOCTYPE> 定义文档类型 4 / 5 none <a> 定 ...
- MySQL 复制
第一步:为配置主数据库与备数据库 主:server_id = 1 log_bin = E:\mysql_log_bin #复制事实上是二进制文件在备库上的重做,所以要支持二进制文件. 备: ...
- PCB打样镀层问题
现在大部分pcb打样所用PCB板一般有锡板和金板之分(一般根据客户要求和产品特 性选择),那么它们有什么区别呢?现在我将他们的区别作比较如下: 1. 从成本方面来说,锡板价格低,金板价格高. 2. 从 ...
- CCNA实验(10) -- Access List
使用包过滤技术在路由器上读取三层及四层报头的信息如源地址.目的地址.源端口.目的端口根据预先定义好的规则对包进行过滤 三种类型:1.标准ACL:表号范围1-99或1300-1999.仅对源IP地址进行 ...