题目描述: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?

输入描述:The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integersa1, 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 thei-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.

输入样例1:

3

3 2 2

输出样例1:

4

输入样例2:

4

2 2 2 2

输出样例2:

3

题目大意:有n个人玩一个游戏 每一轮游戏都需要一个裁判 其余n-1个人是玩家 现在这n个人每个人都有想当玩家的轮数a1,a2.......an 求最少需要玩多少轮能是这n个人每个人都能玩到自己想当玩家的轮数.

输入输出解释:

输入两行  第一行是n个人 第二行是这n个人每个人想当玩家的轮数

思路:

这n个人中 必然有相当玩家轮数最多的那个人 因此 要玩的轮数至少得是max(a1,a2,.....an),我们先这样分析:刚开始,所有的人想当玩家的轮数之和为:sum(a1,a2,....an),而在每一轮游戏中,都会有n-1个人相当玩家的次数减少1,也就是sum每一次游戏减少n - 1,最终经过k轮sum小于等于0,这也就是最终的状态,sum<=0,因此,我们只需要求这个k,而这个k其实很容易求,其实k = [sum / (n - 1)],其中[]是向上取整符号,当求出这个k后,我们还需要进一步判断:当k < max(ai,a2,....an)时,代表在max(a1,a2,....an)轮之前每个人想当玩家的轮数之和就小于等于0了,这是因为,当一些人相当玩家的轮数为0时,后面的每一轮其实都必要再减去n-1了,因为这些人已经不可以再减了,这就会导数在max(a1,a2,..an)轮之前sum<=0,而因为我们最少需要玩的轮数应该是max(a1,a2,....an)轮,因此,此时我们要输出的就是max(a1,a2,...an)轮。而当k >= max(a1,a2,...an)轮时,这个k就是我们要找的最小的满足使n个人都能玩到自己相当玩家轮数的轮数。这道题目整体考虑的还是数学知识,这个规律也是我列了几组数据之后发现的,总的来说,我们要求的k的公式如下:

k = max(max(a1,a2,...an),[sum / (n - 1)]);//[]为向上取整符号

代码如下:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 100000;
int main(void)
{
    long long int sum,Max,a[N],i,n,m;
    scanf ("%lld",&n);
    Max = -1;
    sum = 0;
    for (i = 0; i < n; i++)
    {
        scanf ("%lld",&a[i]);

//边输入每个人相当玩家的轮数边求想当玩家次数最多的玩家相当玩家的次数
        if(Max == -1 ||a[i] > Max)
        {
            Max = a[i];
        }

//边输入边求每个人相当玩家的次数之和
        sum += a[i];
    }
    m = sum / (n - 1);

//将m向上取整
    if(m * (n - 1) < sum)
    {
        m++;
    }

//将m和max(a1,a2,....an)比较,如果比max(a1,a2,....an)小,则应该玩的轮数为max(a1,a2,....an)轮,否则为m轮
    if(m < Max)
    {
        m = Max;
    }

//输出m轮
    printf ("%lld\n",m);

return 0;
}

codefoces384A-Mafia心得的更多相关文章

  1. 我的MYSQL学习心得(一) 简单语法

    我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...

  2. NoSql数据库使用半年后在设计上面的一些心得

    NoSql数据库这个概念听闻许久了,也陆续看到很多公司和产品都在使用,优缺点似乎都被分析的清清楚楚.但我心里一直存有一个疑惑,它的出现究竟是为了解决什么问题? 这个疑惑非常大,为此我看了很多分析文章, ...

  3. 我的MYSQL学习心得(二) 数据类型宽度

    我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...

  4. 我的MYSQL学习心得(三) 查看字段长度

    我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...

  5. 我的MYSQL学习心得(四) 数据类型

    我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(五) 运 ...

  6. 我的MYSQL学习心得(五) 运算符

    我的MYSQL学习心得(五) 运算符 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  7. 我的MYSQL学习心得(六) 函数

    我的MYSQL学习心得(六) 函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

  8. 我的MYSQL学习心得(七) 查询

    我的MYSQL学习心得(七) 查询 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

  9. 我的MYSQL学习心得(八) 插入 更新 删除

    我的MYSQL学习心得(八) 插入 更新 删除 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得( ...

  10. 我的MYSQL学习心得(九) 索引

    我的MYSQL学习心得(九) 索引 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类 ...

随机推荐

  1. oracle temporary table

    oralce 有两种临时表  a.会话级临时表 b.事物级临时表 A.事物级临时表 语法 create  global temporary table table_name( col1  type1, ...

  2. 多个code.csdn.net账号切换

    code.csdn.net是国内开源库 使用git需要在项目添加密钥 而如果有多个账户,一个是私人,一个是公司,那么这时怎么做? 密钥存在~/.ssh默认是id_rsa 那么一个比较笨的办法是做一个k ...

  3. 【ASP.NET MVC 学习笔记】- 14 HtmlHlper的扩展方法

    本文参考:http://www.cnblogs.com/willick/p/3428413.html 1.在 MVC 中用于生成 Html 元素的辅助类是 System.Web.Mvc 命名空间下的  ...

  4. 217. Contains Duplicate (leetcode)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  5. phalcon——闪存消息

    使用两种适配器来定义消息传递给Flasher后的行为: (1)Phalcon\Flash\Direct:直接输出传递给flasher的消息 (2)Phalcon\Flash\Session:将消息临时 ...

  6. MySQL(十六)之MySQL用户管理

    一.MySQL用户管理概述 MySQL是一个多用户的数据库,MYSQL的用户可以分为两大类: 超级管理员用户(root),拥有全部权限 普通用户,由root创建,普通用户只拥有root所分配的权限 二 ...

  7. Python[1,1]

    ####################################################################################### //只是为了凑够150字 ...

  8. Java web学习 Cookie&&Session

    cookie&&session 会话技术 从打开一个浏览器访问某个站点,到关闭这个浏览器的整个过程,成为一次会话.会 话技术就是记录这次会话中客户端的状态与数据的. 会话技术分为Coo ...

  9. IE10和IE11中滑动条遮挡页面问题

    今天在开发的过程中前端项目,在小设备上会出现滑动条,这本没什么,在其他浏览器上都很正常,但是在IE10和IE11上出现了问题,发现侧边滑动条挡住了一部分页面的内容,因为侧边有要操作的按钮,这就是一个很 ...

  10. Leetcode题解(十七)

    48.Rotate Image 题目: 分析:题目意思很简单,就是将一个n*n的矩阵顺时针旋转90度. 这道题难度不大,按照旋转的过程走一遍即可.代码如下: class Solution { publ ...