LightOJ - 1148 - Mad Counting

先上题目:

1148 - Mad Counting

  PDF (English) Statistics Forum
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个人支持他们支持的球队的村民(除了他自己以外)还有多少人,问村子里面至少有多少人。

  不多说,分析一下就可以出结果。

上代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <utility>
 5 #define MAX 1000002
 6 #define ll long long
 7 using namespace std;
 8
 9 typedef pair<ll,int> pii;
10
11 ll s[52];
12 pii p[52];
13
14 int main()
15 {
16     int n,t,x,lo;
17     ll ans;
18     //freopen("data.txt","r",stdin);
19     scanf("%d",&t);
20     for(int z=1;z<=t;z++){
21         scanf("%d",&n);
22         for(int i=0;i<n;i++){
23             scanf("%d",&x);
24             s[i]=x+1;
25         }
26         sort(s,s+n);
27         memset(p,0,sizeof(p));
28         lo=0;
29         p[0].first=s[0];    p[0].second=1;
30         for(int i=1;i<n;i++){
31             if(p[lo].first==s[i]) p[lo].second++;
32             else{
33                 lo++; p[lo].first=s[i]; p[lo].second=1;
34             }
35         }
36         ans=0;
37         for(int i=0;i<=lo;i++){
38             if(p[i].first==p[i].second) ans+=p[i].second;
39             else if(p[i].first<p[i].second){
40                 ans+=p[i].second/p[i].first*p[i].first;
41                 if(p[i].second%p[i].first!=0) ans+=p[i].first;
42             }else{
43                 ans+=p[i].first;
44             }
45         }
46         printf("Case %d: %lld\n",z,ans);
47     }
48     return 0;
49 }

/*1148*/

LightOJ - 1148 - Mad Counting,布布扣,bubuko.com

时间: 2024-10-20 12:03:29

LightOJ - 1148 - Mad Counting的相关文章

LightOJ - 1148 Mad Counting(坑)

Mad Counting Time Limit: 500MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive a

light oj 1148 - Mad Counting

1148 - Mad Counting   PDF (English) Statistics Forum 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 p

1148 - Mad Counting(数学)

1148 - Mad Counting   PDF (English) Statistics Forum 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 p

LightOj 1148 Basic Math

1148 - Mad Counting PDF (English) Statistics Forum 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 pro

LightOJ - 1058 - Parallelogram Counting(数学,计算几何)

链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets o

lightoj Basic Math 数论基础

这里是除去Beginners Problems后的部分 1020 - A Childhood Game 巴什博奕(Bash Game) #include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n; char s[10]; scanf("%d",&t); while(t--) { scanf("%d%s",&n,&s); prin

Light OJ 1148

1148 - Mad Counting 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

light oj Basic Math 数论基础

这里是除去Beginners Problems后的部分 1020 - A Childhood Game 巴什博奕(Bash Game) #include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n; char s[10]; scanf("%d",&t); while(t--) { scanf("%d%s",&n,&s); prin

LightOJ 1307 Counting Triangles 二分查找

[题解整理]二分题 题目类型: 二分查找: 二分答案. 大致解题思路: 查找注意有序和返回值: 浮点数注意精度: 整数注意返回值,建议另外维护一个变量,用于储存可行解. 题目 分类 传送门 WA点 poj 2785 二分查找 题解 lightoj 1088 二分查找 题解 lightoj 1307 二分查找 题解 longlong poj 2456 整数二分答案 题解 poj 3104 整数二分答案 题解 poj 3258 整数二分答案 题解 poj 3273 整数二分答案 题解 lightoj