链接:

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

最新文章

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

热门文章

  1. STM32之spi管理模式
  2. Redis--set类型操作命令
  3. Git学习记录(一)
  4. Git和Github的介绍、简单操作、冲突(上)
  5. Hibernate定义
  6. [Luogu5327][ZJOI2019]语言(树上差分+线段树合并)
  7. 记录MindSphere On Cloud Foundry的一次尝试过程
  8. C#Modbus Rtu的实现
  9. element-ui default-checked-keys 会把节点下所有子节点全部勾选解决方法
  10. 在vue项目中使用live2d