Codeforces Round #202 (Div. 1) A. Mafia 【二分】
2 seconds
256 megabytes
standard input
standard output
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integersa1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use thecin, cout streams or the %I64d specifier.
3 3 2 2
4
4 2 2 2 2
3
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
如果可以进行游戏,那么必定每次游戏都会有一个人当裁判。所以判断是否可以进行游戏的条件就是检查对于n次游戏,是否都有n个人充当裁判。进行二分就十分简单了。
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std;__int64 n, a[100100];bool judge(__int64 x) {__int64 cnt = 0;for (__int64 i = 0; i < n; i++) {//脑残,没注意这个条件,导致一直WAif (x < a[i]) return false;cnt += x - a[i];}return x <= cnt; } int main() {while (cin>>n) {for (__int64 i = 0; i < n; i++) cin>>a[i];__int64 lb = 0, ub = 1e12;__int64 ans = 0;while (ub >= lb) {__int64 mid = (lb + ub)>>1;if(judge(mid)) {ans = mid;ub = mid - 1;}else lb = mid + 1;}cout<<ans<<endl;}return 0; }
转载于:https://www.cnblogs.com/cniwoq/p/6770908.html
Codeforces Round #202 (Div. 1) A. Mafia 【二分】相关推荐
- Codeforces Round #202 (Div. 1): D. Turtles(Lindström–Gessel–Viennot lemma定理+DP)
题意: 给你一个n*m的地图,"#"是障碍,"."是路,不能走出边界,问从(1,1)到(n,m)选出两条不相交最短路径的方案数是多少(其中起点和终点相同不算相交 ...
- Codeforces Round #593 (Div. 2) D. Alice and the Doll 暴力 + 二分
传送门 文章目录 题意: 思路: 题意: 思路: 还以为这个题有什么高深的算法,结果就是个暴力. 由于n∗mn*mn∗m达到了1e101e101e10的级别,所以直接暴力肯定是不行的,考虑有很多空格, ...
- Codeforces Round #725 (Div. 3) G. Gift Set 二分
传送门 文章目录 题意: 思路: 题意: 有两种物品分别有x,yx,yx,y个,每次可以从一个拿出aaa个,另一个拿出bbb个分成一组,问最多能分成多少组. 思路: 这个题有一个显然的单调性,所以二分 ...
- Codeforces Round #635 (Div. 2) D. Xenia and Colorful Gems 暴力 + 二分
传送门 文章目录 题意: 思路: 题意: 给你三个数组a,b,ca,b,ca,b,c,让你从每个数组中选择一个数x,y,zx,y,zx,y,z,使得(x−y)2+(x−z)2+(y−z)2(x-y)^ ...
- Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...
- Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...
- Codeforces Round #514 (Div. 2)题解
Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...
- Codeforces Round #739 (Div. 3)(AK实况)
Codeforces Round #739 (Div. 3) A. Dislike of Threes 找到第kkk个既不是333的倍数,个位数上也不是333的数,也已预处理然后O(1)O(1)O(1 ...
- Codeforces Round #653 (Div. 3)(A, B, C, D, E1详解)
Codeforces Round #653 (Div. 3) Required Remainder Thinking(binary search) 既然是找最大值问题,我又懒得去推式子,于是我直接就上 ...
最新文章
- 读后感与机翻《人类因果学习的分解:自下而上的联想学习和自上而下的图式推理》
- 3-3-完全二叉树结点数
- 深度对比Python(Numpy,Scipy)与Matlab的数值精度
- JSP简单练习-上传文件
- Python小白的数学建模课-03.线性规划
- 如何在20分钟内批量部署20台ESXi服务器?
- office韩文版本
- python数据挖掘的基本流程有哪些?
- android translateanimation动画,Android 动画之TranslateAnimation应用详解
- 软件测试面试中90%会遇到的问题:“你会搭建测试环境吗?”
- matlab中kesi是什么意思,matlab作业简要分析
- pdf添加水印的方法,pdf加水印步骤
- Hive环境搭建--轻量级安装so easy!
- 机器学习Sklearn Day4
- 在微信小程序中使用iconfont
- 浏览器获取cookie失败,浏览器解决方案
- 实例学习Ansible系列(19)drop-if-exist不出错的写法
- 【面经】万得wind测试一面13min
- Linux安装卸载java
- 鸿蒙座舱子品牌来了,华为发布 HarmonySpace:万物互联的智能出行空间