zoukankan      html  css  js  c++  java
  • CF996B World Cup 思维 第十四 *

    World Cup
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Allen wants to enter a fan zone that occupies a round square and has nn entrances.

    There already is a queue of aiai people in front of the ii-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.

    Allen uses the following strategy to enter the fan zone:

    • Initially he stands in the end of the queue in front of the first entrance.
    • Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance).

    Determine the entrance through which Allen will finally enter the fan zone.

    Input

    The first line contains a single integer nn (2n1052≤n≤105) — the number of entrances.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (0ai1090≤ai≤109) — the number of people in queues. These numbers do not include Allen.

    Output

    Print a single integer — the number of entrance that Allen will use.

    Examples
    input
    Copy
    4
    2 3 2 0
    output
    Copy
    3
    input
    Copy
    2
    10 10
    output
    Copy
    1
    input
    Copy
    6
    5 2 6 5 7 4
    output
    Copy
    6
    Note

    In the first example the number of people (not including Allen) changes as follows: [2,3,2,0][1,2,1,0][0,1,0,0][2,3,2,0]→[1,2,1,0]→[0,1,0,0]. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.

    In the second example the number of people (not including Allen) changes as follows:[10,10][9,9][8,8][7,7][6,6][5,5][4,4][3,3][2,2][1,1][0,0][10,10]→[9,9]→[8,8]→[7,7]→[6,6]→[5,5]→[4,4]→[3,3]→[2,2]→[1,1]→[0,0].

    In the third example the number of people (not including Allen) changes as follows:[5,2,6,5,7,4][4,1,5,4,6,3][3,0,4,3,5,2][2,0,3,2,4,1][1,0,2,1,3,0][0,0,1,0,2,0]

    #include <map>
    #include <set>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <vector>
    #include <string>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define debug(a) cout << #a << " " << a << endl
    using namespace std;
    const int maxn = 1e5 + 10;
    const int mod = 1e9 + 7;
    typedef long long ll;
    ll a[maxn];
    int main(){
        std::ios::sync_with_stdio(false);
        ll n;
        while( cin >> n ) {
            ll maxm = 1e12, sum = n;
            for( ll i = 1; i <= n; i ++ ) {
                cin >> a[i];
                a[i] -= i - 1;
                if( maxm > ( a[i] + n - 1 ) / n ) {
                    maxm = ( a[i] + n - 1 ) / n;
                    sum = i;
                }
            }
            cout << sum << endl;
        }
        return 0;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    jdbc和DBeaver客户端连接oracle很慢,初始化连接成功后速度正常
    centos7中vncserver连接失败
    postgres数据库建库、修改owner
    nested exception is org.apache.ibatis.binding.BindingException:
    postgresql导出表insert方式数据
    解决ecllipse注释模板不生效问题
    postgresql 修改表属性,包括新增、修改、删除列
    ssh本机可登陆远端服务器,但远端服务器无法登陆本机
    linux源码安装后,设置动态库路径和环境变量
    valgrind跟踪调试动态库*.so
  • 原文地址:https://www.cnblogs.com/l609929321/p/9225543.html
Copyright © 2011-2022 走看看