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

2

4

1 1 2 2

1

0

Sample Output

Case 1: 5

Case 2: 1

Source

Problem Setter: Muhammad Rifayat Samee

Special Thanks: Jane Alam Jan

Submit Status

什么鬼? 相等的话跳过只加被询问的人 ; 然后对最后相等的数进行处理相加 ;

#include <cstdio>
#include <algorithm>
#define N 51
int a[N];
using namespace std;
int main()
{
    int t; int Q=1;
    scanf("%d", &t);
    while(t--)
    {
        int n;
        scanf("%d", &n);
        for(int i=0; i<n; i++)
            scanf("%d", &a[i]);
        sort(a, a+n);
        int cnt=0, sp=0;
        for(int i=0; i<n; i++)
        {
            if(i==0 || a[i]==a[i-1]) cnt++;
            else
            {
                int k=(cnt+a[i-1]) / (a[i-1]+1);
                sp=sp+k*(a[i-1] + 1);
                cnt=0;
            }
        }
        sp=sp+(cnt+a[n-1])/(a[n-1]+1) *(a[n-1]+1);
        printf("Case %d: %d\n", Q++, sp);
    }
    return 0;
}
时间: 2024-11-01 04:32:08

LightOJ - 1148 Mad Counting(坑)的相关文章

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

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