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. ...
随机推荐
- 题解 CF1216C 【White Sheet】
虽然也很水,但这道还是比前两道难多了... 题目大意:给你三个位于同一平面直角坐标系的矩形,询问你后两个是否完全覆盖了前一个 首先,最直观的想法应该是,把第一个矩形内部每个整数点检查一下,看看是否位于 ...
- golang之文件结尾错误(EOF)
函数经常会返回多种错误,这对终端用户来说可能会很有趣,但对程序而言,这使得情况变得复杂.很多时候,程序必须根据错误类型,作出不同的响应.让我们考虑这样一个例子:从文件中读取n个字节.如果n等于文件的长 ...
- loginserver 个人草稿
<script> (function($, doc) { /*var contextpath = "http://192.168.0.102:8080/pwgtjq"; ...
- dotnet Core 图片验证码
9102年了,.NET Core 2.x已经稳定,但是还是有很多人搞不定.NET Core的图片验证码. 下面说重点 1.引用Nuget包:System.Drawing.Common 2.像NET F ...
- 题解-CSA Round#18 Randomly Permuted Costs
Problem CSA Round 18 题意概要:给定一个有重边有自环 \(n\) 点 \(m\) 边的有向无环图(DAG),每条边有其权值,每当你走到一个点 \(x\) 时,所有从 \(x\) 连 ...
- linux安装imagemagick,centos安装imagemagick方法
1.安装文件格式支持库 yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype- ...
- is 和 as 使用
类型判断 as: var newParser = parser as ClassA ; 转为ClassA类型赋值给newParser is: var flag = parser is ClassA ; ...
- C#从零单排上王者系列---数据类型
从零单排系列简介 突然发现自己的基础不是很牢固,就买了一个<C#7.0的本质论>.本系列博客就是以此书为本,记录自己的学习心得,如果你的基础也不牢固,不如跟上博主一起学习成长呀! 本篇博客 ...
- 有用的vscode快捷键大全+自定义快捷键
VS Code是前端的一个比较好用的代码编辑器,但是我们不能老是局限于鼠标操作呀,有时候很不方便,所以呢,快捷键大全来啦,有的可能会和你们电脑自带的快捷键冲突呢,这时候,你自己设置一下就好了呀 一.v ...
- Shell 脚本操作数据库实战
安装mariadb 数据库 (默认没有密码,直接mysql即可进入数据库管理控制台) yum install mariadb mariadb-server mariadb-libs -y syste ...