LightOJ - 1148-Mad Counting (数学)
2024-08-27 10:47:13
链接:
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;
}
最新文章
- 使用命令行备份指定文件夹并保留最新N份
- 【C语言】02-第一个C程序
- dump java
- gcc、g++
- linux时间管理
- shell获取本地ip的三种方法
- 学习笔记 css3--选择器&;新增颜色模式&;文本相关
- android 代码布局 记录
- 使用virtualenv隔离python环境
- python爬行动物集合360联想词搜索
- SQLSERVER一些公用DLL
- 提高java编程质量 - (三)三目运算符的两个操作数类型尽量一致
- EventBus In eShop -- 解析微软微服务架构Demo(四)
- DataGridView设置行高
- gentoo hibernate
- ldap集成jenkins
- InfluxDB学习之InfluxDB的基本操作| Linux大学
- 原生JavaScript技巧大收集(1~10)
- JAVA-JSP内置对象之pageContext对象
- 在eclipse中创建web项目(非myeclipse)