码迷,mamicode.com
首页 > 其他好文 > 详细

LightOJ - 1148-Mad Counting (数学)

时间:2019-11-12 13:28:08      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:case   http   scan   pop   tps   def   world   rom   app   

链接:

https://vjudge.net/problem/LightOJ-1148

题意:

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.

思路:

报数n的人,最多n+1个组成一队,取最优计算

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>

using namespace std;
typedef long long LL;
const int INF = 1e9;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;

map<int, int> Mp;

int main()
{
    int t, cnt = 0;
    int n, x, v;
    scanf("%d", &t);
    while(t--)
    {
        Mp.clear();
        scanf("%d", &n);
        printf("Case %d: ", ++cnt);
        for (int i = 1;i <= n;i++)
        {
            scanf("%d", &v);
            Mp[v]++;
        }
        int sum = 0;
        for (auto v: Mp)
        {
            sum += ((v.second+v.first)/(v.first+1))*(v.first+1);
        }
        printf("%d\n", sum);
    }

    return 0;
}

LightOJ - 1148-Mad Counting (数学)

标签:case   http   scan   pop   tps   def   world   rom   app   

原文地址:https://www.cnblogs.com/YDDDD/p/11841059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!