当前位置:编程学习 > C/C++ >>

CF 348A(Mafia-判定性问题)

A. Mafia
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output 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?
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 test(s)
input
3
3 2 2
output
4
input
4
2 2 2 2
output
3
Note
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.易做图.org/wiki/Mafia_(party_game).
 
 
 
这题如果硬解没思路,但是判断一个答案就是很简单。
然后你懂得。。
因为用了int惨遭Hack,各种NC。。。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n;
ll a[MAXN];
int main()
{
	cin>>n;
	For(i,n) cin>>a[i];
	ll k=0;
	For(i,n) k=max(k,a[i]);
	ll t=0;
	For(i,n) t+=k-a[i];
	if (t>=k) {cout<<k<<endl;return 0;	}
	else 
	{
		double p=((double)(k-t))/((double)(n-1));
		k+=ceil(p);
		cout<<k<<endl;
	}
	
	return 0;
}

 


补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,