博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1148 - Mad Counting(数学)
阅读量:6907 次
发布时间:2019-06-27

本文共 2377 字,大约阅读时间需要 7 分钟。

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即可,那么代码救出来了;

代码:

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 using namespace std;11 const int INF=0x3f3f3f3f;12 const int MAXN=1e6+10;13 int pre[MAXN];14 int a[MAXN];15 int main(){16 int T,N,temp,flot=0;17 scanf("%d",&T);18 while(T--){19 memset(pre,0,sizeof(pre));20 scanf("%d",&N);21 int pos=0;22 for(int i=0;i

 再次出了这个题,代码;

 

#include
#include
#include
#include
#include
#include
#include
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
temp)sum+=temp,flot=1; } printf("Case %d: %d\n",++kase,sum); } return 0;}

  

  

转载地址:http://pmgdl.baihongyu.com/

你可能感兴趣的文章
C#.NET学习笔记1---C#.NET简介
查看>>
oracle修改字符集后数据库不能启动
查看>>
jQuery缓存机制(三)
查看>>
2014第10周日
查看>>
174. Dungeon Game
查看>>
Brackets
查看>>
Mac系统下lipo, ar, nm等工具的使用简介
查看>>
前端解决跨域问题的8种方案(最新最全)
查看>>
Linux技巧学习
查看>>
微信小程序开发02-小程序基本介绍
查看>>
android studio C/C++ jni 编写以及调试方法
查看>>
我们在囧途之年终奖篇
查看>>
JAVA数组之选择排序算法
查看>>
初窥Linux 之 数据流重定向
查看>>
Ubuntu SVN安装&使用&命令
查看>>
文件上传小技巧/后端处理【以php示例】
查看>>
spring boot 项目启动无任何反应
查看>>
ASP.NET Core 2.1 : 十.升级现有Core2.0 项目到2.1
查看>>
架构师修炼之路
查看>>
会人之不会成为能
查看>>