B. World Cup(思维)

B. 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][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].


Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

题意:小明去看世界杯,有n条入口形成一个环,每条入口有ai个人排队进场,小明首先排在第一条队伍的最后面,每个入口每分钟可以进入1个人,小明是个闲不住的人,如果这一分钟不是小明进场的话,他就会移动到下一队的队尾(没有后续的人来排队)。问小明最后是在几号入口进入球场的。


思路:求出小明从每个入口进入需要的时间,然后取最小的,mod  入口的个数,就是答案了。(很容易就想到,入场的时间,其实就是小明移动的步数,只有当小明刚好移动到这个入口,并且这个入口排队的人数为0,小明才可以进入,由于入口是形成一个环的,步数mod入口数就是小明入场的入口编号了)注意,这里需要用到long long


#include "iostream"
using namespace std;
typedef long long ll;
const int Max=1e5+10;
const int inf=1e18;
int a[Max];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    ll t,ans=inf,x;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        if(i-1>=a[i]) {ans=i;break;}//如果到这个入口,人数已经为0,直接进入
        else{//求出步数
            x=(a[i]-(i-1))%n?((a[i]-(i-1))/n)+1:((a[i]-(i-1))/n);
            t=x*n+i;
        }
        ans=ans<t?ans:t;//更新最小步数
    }
    ans%=n;
    if(ans==0) ans=n;
    cout<<ans<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41874469/article/details/80807496