C
来源:互联网 发布:淘宝竞价推广 编辑:程序博客网 时间:2024/06/11 08:49
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 %I64dspecifier.
Sample Input
33 2 2
4
42 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个人玩捉迷藏,在输入每个人必须玩的局数,让你求最小需要进行几局。
解题思路:
一开始考虑的n-1个人,发现太复杂,然后从裁判的角度入手,比如第一组数据,首先次数肯定是不能小于最大的数,假设是3,那么第一个人要最多当0次裁判,第二个人最多当1次裁判,第三个人最多当1次裁判,且加起来的次数要至少达到3才行。如若不行,则最大数加一,而减去最大数的和再加上n。
解题细节:
注意题目的数据应该足够大,要使用longlong。
代码:
#include <iostream> using namespace std; int main() { long long n,i; while(cin>>n) { long long a[100001]; long long max=0,sum=0; for(i=0;i<n;i++) { cin>>a[i]; if(a[i]>max) max=a[i]; } for(i=0;i<n;i++) { a[i]=max-a[i]; sum+=a[i]; } for(i=0;i<1999999999;i++) { if(sum>=max) { cout<<max; break; } else { sum+=n; max++; } } } return 0; }
解题心得:
想问题要从多个角度去思考,不能束缚自己的思维,多方面考虑。
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- Redis (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persis
- 算法练习之(任意长度字符串逆向输出)
- 机器学习之层次聚类及代码示例
- 求全1的最大正方形的边长 和 全1的最大子矩阵的面积 和POJ 2559 最大直方图
- JsonPath教程
- C
- linux中文件操作函数
- 自动拆装箱
- gdb调试linux系统调用
- CSDN-markdown编辑器使用教程
- Pdf File Writer 中文应用(PDF文件编写器C#类库)
- Winsock 10053错误分析
- 关于java中参数传递的简单理解
- 说一说提问的那些事