codeforces Mafia
/*
* Mafia.cpp
*
* Created on: 2013-10-12
* Author: wangzhu
*/ /**
* 每个人都想玩若干场,求至少需要玩几场才可以满足大家的需求。
* 结果必然在某个人想玩的次数nmax(此人想玩的是最多的)与所有人想玩的次数和sum之间,
* 故二分,left = nmax,right = sum,
* 只需要需要玩的次数 * (总人数-1) >= 大家想玩的次数和即可
*
*/
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
#define NMAX 100010
int arr[NMAX];
LL binary(int n, int nmax, LL sum) {
LL mid = -, left = nmax, right = sum;
while (left <= right) {
mid = left + (right - left) / ;
if (sum <= (mid * n)) {
right = mid - ;
} else {
left = mid + ;
}
}
return left;
}
int main() {
freopen("data.in", "r", stdin);
int n, nmax;
LL sum;
while(~scanf("%d",&n)) {
nmax = -;
sum = ;
for(int i = ;i < n;i++) {
scanf("%d",arr + i);
if(nmax < arr[i]) {
nmax = arr[i];
}
sum += arr[i];
}
printf("%I64d\n",binary(n - ,nmax,sum)); }
return ;
}
codeforces Mafia的更多相关文章
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- CodeForces - 348A Mafia (巧妙二分)
传送门: http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory li ...
- Codeforces Round #202 (Div. 1) A. Mafia 推公式 + 二分答案
http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory limit p ...
- Codeforces Gym 100733H Designation in the Mafia flyod
Designation in the MafiaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...
- Codeforces 348A Mafia
题目链接:http://codeforces.com/problemset/problem/348/A 题目大意:N个人中找出1个人主持,剩下N-1个人参与游戏,给出每个人想参与游戏的次数,问要满足每 ...
- Codeforces 349C - Mafia
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 587D - Duff in Mafia(2-SAT+前后缀优化建图)
Codeforces 题面传送门 & 洛谷题面传送门 2-SAT hot tea. 首先一眼二分答案,我们二分答案 \(mid\),那么问题转化为,是否存在一个所有边权都 \(\le mid\ ...
- 【Codeforces 348A】Mafia
[链接] 我是链接,点我呀:) [题意] 每轮游戏都要有一个人当裁判,其余n-1个人当玩家 给出每个人想当玩家的次数ai 请你求出所需要最少的玩游戏的轮数 使得每个人都能满足他们当玩家的要求. [题解 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- JAXB - Annotations, Class Fields as Attributes: XmlAttribute
Provided that XML lets you represent a data item as a single value, there is no cut-and-dried rule f ...
- asp:时间的显示
DateTime dt = DateTime.Now;// Label1.Text = dt.ToString();//2005-11-5 13:21:25// Label2.Text = ...
- ajax和jsonp的封装
一直在用jQuery的ajax,跨域也是一直用的jQuery的jsonp,jQuery确实很方便,$.ajax({...})就可以搞定. 为了更好的理解ajax和jsonp,又重新看了下书,看了一些博 ...
- FreeMarker语法2
FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主要由如下4个部分组成: 1,文本:直接输出的部分 2,注释:<#-- ... -->格式部分,不会输 ...
- extern int a[] VS extern int *a
array VS pointer 参考: 1.Extern using pointer instead of array array is not pointer 2.extern array que ...
- Python快速入门学习笔记(一)
本篇文章适合有其他高级语言基础的人群阅读 使用的Python版本为python2.7 使用的编辑器为Sublime Text3 世界始于Hello World: print 'Hello world' ...
- springmvc学习(一)helloworld实例
今天介绍的是springmvc的学习,越来越多的企业开始选择springmvc+mybatis来构建系统架构,在电商热门的今天,springmvc+mybatis已成为电商项目架构的很好搭配.Spri ...
- C++对象模型与内存位对齐的简单分析(GNU GCC&VS2015编译器)
以Fruit和Apple为例进行分析: Fruit和Apple的定义如下: 通过在两种编译环境下的测试(GNU GCC & VS2015),可以发现这两种编译器的对象模型是一样的,如下图所示: ...
- Newtonsoft.Json.dll解析json的dll文件使用
要解析的json //解析前 //解析前 {,,,,,,,,,,},,,,,,,,,,,},,,,,,,,,,,,,,,,},,,,,,,,,},,,,,,,,,,,,},,,,,,,,,,,},,, ...
- laravel1
生成模型的时候 同时生成migration文件php artisan make:model User --migration