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(数学)的更多相关文章

  1. lightoj 1148 Mad Counting(数学水题)

    lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...

  2. light oj 1148 - Mad Counting

    1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...

  3. LightOJ - 1148 - Mad Counting

    先上题目: 1148 - Mad Counting   PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...

  4. Codeforces 911D. Inversion Counting (数学、思维)

    题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...

  5. 17997 Simple Counting 数学

    17997 Simple Counting 时间限制:2000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: 不限定 Description Ly is craz ...

  6. 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. ...

  7. LightOj 1148 Basic Math

    1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob ...

  8. acdream.A Very Easy Triangle Counting Game(数学推导)

    A - A Very Easy Triangle Counting Game Time Limit:1000MS     Memory Limit:64000KB     64bit IO Forma ...

  9. UVALive 5058 Counting BST 数学

    B - Counting BST Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

随机推荐

  1. calltree看代码调用图

    calltree是在linux下面看c代码(尤其是复杂的内核代码)的神器. 推荐  calltree+vim + ctags + cscope + taglist [ vim: 搭建vim看代码的环境 ...

  2. Android Listview切换动画,扩展到任意view切换之间动画实现

    添加布局如下: <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2010 ...

  3. ThinPHP第二十八天(F函数和file_put_contents区别|PHP生成PHP文件,Kindeditor编辑器使用方法)

    1.F(name,data,path)函数和file_put_contents(file,str)区别 F函数直接生成<?php ?>格式的php文件了,将data加入到<?php和 ...

  4. egret命令行编译项目时 版本不对应的问题

    egret 命令行编译项目时 如使用 egret build -e 会出现版本不对应的问题 分析原因 A,B项目 A项目使用1.8的egret引擎, B项目使用2.5引擎 但本地引擎升级至2.5.5, ...

  5. 【LeetCode题意分析&解答】36. Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  6. C#进程管理程序实现

    运行效果图 部分代码如下: #region 打开应用程序按钮事件处理程序 /// <summary> /// 打开应用程序按钮事件处理程序 /// </summary> /// ...

  7. PCB成型製程介紹

    PCB成型製程在電子構裝中所扮演的角色 下圖是電腦主機的內部組成 我們將以插在主機板上的一片 USB擴充卡來說明PCB成型製 程在電子構裝中所扮演的角色 PCB成型製程的子製程 USB擴充卡要插入主機 ...

  8. Html 小插件2

    调用google的JS翻译插件实现页面自动翻译功能 网址http://translate.google.com/translate_tools 设置自己需要的配置生成如下代码放到自己站的页面头部 代码 ...

  9. C模块回调Lua函数的两种方法

    作者:ani_di 版权所有,转载务必保留此链接 http://blog.csdn.net/ani_di C模块回调Lua函数的两种方法 lua和C通过虚拟栈这种交互方式简单而又可靠,缺点就是C做栈平 ...

  10. Android布局_LinearLayout布局

    一.LinearLayout 布局,类似于一个盒子 1. 主要属性有: (1)android:orientation 设置LinearLayout容器布局组件的方式:要么按行要么按列.只能取值:hor ...