LightOJ - 1148-Mad Counting (数学)
链接:
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 (数学)的更多相关文章
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- LightOJ - 1148 - Mad Counting
先上题目: 1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 3 ...
- 1148 - Mad Counting(数学)
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...
- light oj 1148 - Mad Counting
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB M ...
- LightOj 1148 Basic Math
1148 - Mad Counting PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB Mob ...
- LightOJ - 1058 - Parallelogram Counting(数学,计算几何)
链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by t ...
- Codeforces 911D. Inversion Counting (数学、思维)
题目链接:Inversion Counting 题意: 定义数列{ai|i=1,2,...,n}的逆序对如下:对于所有的1≤j<i≤n,若ai<aj,则<i,j>为一个逆序对. ...
- LightOJ 1058 - Parallelogram Counting 几何思维
http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...
- 17997 Simple Counting 数学
17997 Simple Counting 时间限制:2000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: 不限定 Description Ly is craz ...
- UVA 11401 - Triangle CountingTriangle Counting 数学
You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. ...
随机推荐
- (一)PlantUML 语法之时序图
文章目录 前言 `-> -->` 信息传递 声明参与者的几个关键字 `as` 重命名参与者 `#` 添加颜色 `order` 定义参与者顺序 `""` 参与者名字 给自 ...
- Python爬虫刷回复
最近闲的无聊,就想着去看看爬虫,顺着爬虫顺利的做到了模拟登录.刷帖子等等,这里简要说一下. 使用Python2.7写的爬虫,对某论坛做模拟登陆和刷帖子.回复等等,由于之前是没有接触过爬虫,这次之后感觉 ...
- window服务器查看管理员列表
快捷键win+R 输入cmd并进入 输入指令net localgroup administrators
- VMWare打开centos,提示内部错误
如题,VMWare打开centos,提示内部错误.该原因是因为服务被停止了之后没有将其启动,将其启动就解决了. CMD客户端输入命令 services.msc 将关于VM的服务启动就可以了
- 代码审计:covercms 1.6
小菜只能找找没人用的cms练练手了 cnvd上有个 CoverCMS V1.16存在多个漏洞 漏洞描述 :CoverCMS V1.16存在重装.信息泄露.暴力破解.存储型跨站脚本和反射型跨站脚本漏洞. ...
- .net通过网络路径下载文件至本地
获取网络文件,通过流保存文件,由于上一版存在数据丢失情况,稍微调整了以下. //网络路径文件 string pathUrl = "http://localhost:805/春风吹.mp3&q ...
- (面试题)请用C语言实现在32位环境下,两个无符号长整数相加的函数,相加之和不能存储在64位变量中
分析:长整数相加,将结果分为高位和低位部分,分别保存在两个32整数中. 比如:unsigned int a = 0xFFFFFFFF, unsigned int b = 0x1, 结果用unsigne ...
- js-Array数组
一.创建数组的两种方式 1.使用Array构造函数 var colors = new Array(); var colors = new Array(20); var colors = new Arr ...
- 记一次有趣的tp5代码执行
0x00 前言 朋友之前给了个站,拿了很久终于拿下,简单记录一下. 0x01 基础信息 漏洞点:tp 5 method 代码执行,payload如下 POST /?s=captcha _method= ...
- nginx 之 https 证书配置
HTTPS原理和作用 为什么需要HTTPS 原因:HTTP不安全 传输数据被中间人盗用.信息泄露 数据内容劫持.篡改 HTTPS协议的实现 对传输内容进行加密以及身份验证 对称加密:加密秘钥和解密秘钥 ...