Codeforces 349C - 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 - 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?
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.
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 the cin, cout streams or the %I64dspecifier.
3
3 2 2
4
4
2 2 2 2
3
题目:
第一步:
那么,
那么我们就可得以下代码:
#include<cstdio>
long long max(long long a,long long b){
if(a>b) return a;
else return b;
}
int a[];
int main()
{
int n;scanf("%d",&n); int max_ai=;
long long sum=;
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
sum+=a[i];
if(max_ai<a[i]) max_ai=a[i];
} if( sum/(double)(n-) == sum/(n-) ) sum=sum/(n-);
else sum=sum/(n-)+; long long ans=max((long long)max_ai,sum);
printf("%I64d\n",ans);
}
Codeforces 349C - Mafia的更多相关文章
- CodeForces - 348A Mafia (巧妙二分)
传送门: http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory li ...
- Codeforces 348A Mafia
题目链接:http://codeforces.com/problemset/problem/348/A 题目大意:N个人中找出1个人主持,剩下N-1个人参与游戏,给出每个人想参与游戏的次数,问要满足每 ...
- 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 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 Mafia
/* * Mafia.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每个人都想玩若干场,求至少需要玩几场才可以满足大家的需求. * ...
- 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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- cocos2d-x 3.0 在lua中调用自定义类
环境 windows8, cocos2d-x 3.0, 现在开始安装需要的一些其它包 1. 按README.mdown文档上面要求的, 下载在windows下要安装的东东, 主要就是python2.7 ...
- 为什么GPL是更好的开源许可证?
1. 让我从一件新闻讲起. 2009年,计算机业界发生了一件大事:甲骨文公司以74亿美元收购SUN公司. 消息宣布后,有一个人坚决反对这笔交易.他叫Michael Widenius,是数据库软件MyS ...
- 使用Bind搭建DNS服务
DNS域名解析服务(Domain Name System)是用于解析域名与IP地址对应关系的服务,功能上可以实现正向解析与反向解析: 正向解析:根据主机名(域名)查找对应的IP地址. 反向解析:根据I ...
- ibatis 引入多个model
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "- ...
- 细说php的异常和错误处理机制
再谈php错误与异常处理 讲的非常好 w3school php异常处理机制 php错误异常处理详解 注: 关注set_error_handler() set_exception_handler() r ...
- JS中方法判断存在
function test(){ alert("test"); } if(typeof test!='undefined') {alert(1) test(); } else {a ...
- ldap objectclass
LDAP中,一个条目必须包含一个objectClass属性,且需要赋予至少一个值.每一个值将用作一条LDAP条目进行数据存储的模板:模板中包含了一个条目必须被赋值的属性和可选的属性. obj ...
- linux计划任务之crontab
语法: crontab [ -u user ] file crontab [ -u user ] [ -i ] { -e | -l | -r } 说明: crontab命令 ...
- 【Spring系列】Spring IoC
前言 IoC其实有两种方式,一种是DI,而另一种是DL,即Dependency Lookup(依赖查找),前者是当前软件实体被动接受其依赖的其他组件被IOc容器注入,而后者是当前软件实体主动去某个服务 ...
- Android.mk (2) 函数进阶教程 - 分支、循环、子程序
https://www.jianshu.com/p/674dc7d7b4b0 函数进阶教程 - 分支.循环.子程序 按照面向过程程序设计的标准流程,我们讲完了顺序结构,就要讲分支.循环和子程序.下面我 ...