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 ...
随机推荐
- google base库之simplethread
// This is the base SimpleThread. You can derive from it and implement the // virtual Run method, or ...
- webService接口大全
中文<->英文双向翻译WEB服务 获得标准数据 Endpoint: http://fy.webxml.com.cn/webservices/EnglishChinese.asmx Disc ...
- C#进程管理程序实现
运行效果图 部分代码如下: #region 打开应用程序按钮事件处理程序 /// <summary> /// 打开应用程序按钮事件处理程序 /// </summary> /// ...
- ny 58 最少步数 (BFS)
题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=58 就是一道简单的BFS 练习练习搜索,一次AC #include <iostream& ...
- php基础知识总结
PHP 代表 PHP: Hypertext Preprocessor PHP 文件可包含文本.HTML.JavaScript代码和 PHP 代码 PHP 代码在服务器上执行,结果以纯 HTML 形式返 ...
- 【转】android权限列表
访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permiss ...
- java 获取随机数的三种方法
方法1(数据类型)(最小值+Math.random()*(最大值-最小值+1))例:(int)(1+Math.random()*(10-1+1))从1到10的int型随数 方法2获得随机数for (i ...
- iOS 按钮倒计时功能
iOS 按钮倒计时功能, 建议把按钮换成label,这样会避免读秒时闪烁 __block ; __block UIButton *verifybutton = _GetverificationBtn; ...
- SSO 基于Cookie+fliter实现单点登录(SSO):工作原理
SSO的概念: 单点登录SSO(Single Sign-On)是身份管理中的一部分. SSO的一种较为通俗的定义是:SSO是指訪问同一server不同应用中的受保护资源的同一用户,仅仅须要登录一次,即 ...
- 倒计时IE6+
很简单的 下面是我为了做多个倒计时更改之后的 dome 下载链接 兼容 IE7以上 IE6没测试应该没问题 http://yunpan.cn/cf29rxmGKuMyJ 提取码 ca61