349B - C. Mafia
Description
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1people 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?
Input
The first line contains integer n(3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an(1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
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 airounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Sample Input
3
3 2 2
4
4
2 2 2 2
3
Hint
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个小朋友玩游戏,这个游戏每轮必须有一个人坐庄(不能玩游戏),其他人参与游戏,每个小朋友都想当ai次玩游戏的人,问
至少多少轮游戏才能满足要求 初步思路:二分,二分的条件就是将所有的小朋友的坐庄的次数和玩游戏的次数和总共需要坐庄的次数比较 #错误:INF开小了
*/
#include <bits/stdc++.h>
#define INF 1e13
using namespace std;
long long a[];
long long maxn=-;
int n;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<n;i++){
cin>>a[i];
maxn=max(maxn,a[i]);
}
long long l=maxn,r=INF,mid,res,ans=-;
while(l<=r){
mid=(l+r)>>;
res=;
for(int i=;i<n;i++){
res+=mid-a[i];
}
if(res>=mid){
ans=mid;
r=mid-;
}else{
l=mid+;
}
}
cout<<ans<<endl;
return ;
}
349B - C. Mafia的更多相关文章
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- [BZOJ1163][BZOJ1339][Baltic2008]Mafia
[BZOJ1163][BZOJ1339][Baltic2008]Mafia 试题描述 匪徒准备从一个车站转移毒品到另一个车站,警方准备进行布控. 对于每个车站进行布控都需要一定的代价,现在警方希望使用 ...
- 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 Mafia
/* * Mafia.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每个人都想玩若干场,求至少需要玩几场才可以满足大家的需求. * ...
- 1339 / 1163: [Baltic2008]Mafia
1163: [Baltic2008]Mafia Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 96 Solved: 60[Submit][Statu ...
- 【CF587D】Duff in Mafia 二分+前缀优化建图+2-SAT
[CF587D]Duff in Mafia 题意:给你一张n个点m条边的无向图,边有颜色和边权.你要从中删去一些边,满足: 1.任意两条删掉的边没有公共的顶点.2.任意两条剩余的.颜色相同的边没有公共 ...
- Codeforces 349C - Mafia
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 349B - Color the Fence
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...
- 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 ...
随机推荐
- java中Set类接口的用法
在Java中使用Set,可以方便地将需要的类型,以集合类型保存在一个变量中.主要应用在显示列表. Set是一个不包含重复元素的collection.更确切地讲,set 不包含满足 e1.equals( ...
- 打印ASCII码
总时间限制:1000ms内存限制:65536kB 描述 输入一个除空格以外的可见字符(保证在函数scanf中可使用格式说明符%c读入),输出其ASCII码. 输入 一个除空格以外的可见字符. 输出 一 ...
- 翻译:MLAPP(2.2节 概率论简要回顾)
笔者:尝试翻译MLAPP(Machine Learning: a Probabilistic Perspective)一书,供机器学习的学者参考,如有错误理解之处请指出,不胜感激!(如需转载,请联系本 ...
- S2_SQL_第二章
第二章:初始mySql 2.1:mySql简介 2.1.2:mysql的优势 运行速度块,体积小,命令执行的块 使用成本低,开源的 容易使用 可移植性强 2.2:mysql的配置 2.2.1:端口配置 ...
- Array Partition I
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1 ...
- MyBatis Generator代码自动生成工具的使用
MyBatis Generator MyBatis Generator有三种使用方式,分别是maven插件形式.命令行形式以及eclipse插件形式.我在这里使用的是命令行的形式(主要是命令行形式比较 ...
- IIS7中JS、CSS、Image无法显示和加载解决方案
前两天把机器从Windows7升级到Windows10,IIS也跟着升级了,在获取项目搭载IIS上发现原有的页面中所有的JS.CSS.Image都无法访问,提示500错误,起初以为是IIS没有装好 重 ...
- DNS—正、反向解析;委派;主从;子域;转发;智能dns等的实现
前言:DNS,耳熟能详的东西,内容太多,小编也不太好讲清,只能写几个实验详解,供大家参考. 一.简单介绍 1.DNS:通过主机名,最终得到该主机名对应的IP地址的过程叫做域名解析(或主机名解析). 端 ...
- python爬虫之获取验证码登陆
#--coding:utf-8#author:wuhao##这里我演示的就是本人所在学校的教务系统#import urllib.requestimport urllib.parseimport rei ...
- This application failed to start because it could not find or load the Qt platform plugin "windows" 的问题原因以及解决方案
1. 问题原因非常简单,经过各种百度,都没有找到解决方案,在此做一个记录备用. 2.原因就在于,项目目录使用了中文路径,然后出现了这个问题. 3.我是在使用 syncfusion 下的HTML 转PD ...