zoukankan      html  css  js  c++  java
  • Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/348/problem/A

    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 - 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?

    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 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 %I64d specifier.

    Sample Input

    3
    3 2 2

    Sample Output

    4

    HINT

    题意

    有n个人,在玩一个游戏,游戏表示每局都必须有个管理员参加

    告诉你,每个人想当多少局玩家,然后让你求,最少多少局游戏,才能满足题意!

    题解:

    贪心就好了,类似厨师煮饼那道题一样

    max(max_num,sum/(n-1));

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)  
    #define maxn 200001
    #define mod 1000000007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    ll a[maxn];
    ll sum=0;
    ll mx=0;
    int main()
    {
        int n=read();
        for(int i=1;i<=n;i++)
            a[i]=read(),sum+=a[i],mx=max(a[i],mx);
        n=n-1;
        ll ans;
        ans=sum/n;
        if(sum%n!=0)
            ans++;
        cout<<max(mx,ans)<<endl;
    }
  • 相关阅读:
    STM32低功耗模式与烟雾报警器触发信号电路设计
    cocos2d-x的环境的搭建
    window8.1中用户的管理员权限的提升方法
    cmd中目录的变更
    js的传值,table中tr的遍历,js中动态创建数组
    究竟什么是游戏引擎?
    大型网站架构学习心德
    关于listView 中的聚焦问题
    android6.0 适配的问题——activity销毁的问题
    文件发送成功率低的问题(2)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4534357.html
Copyright © 2011-2022 走看看