Codeforces Round #492 (Div. 2) B. World Cup 思维题

版权声明:《学习技巧》每次使用单边大脑的时间不要太久,连续使用左边大脑30分钟就如同连续使用左臂30分钟一样,周期性的交换让大脑两侧能够轮流休息,左脑活动包括了循序渐进的工作,解决逻辑问题与分析,而右脑活动包括了隐喻,创造性思考,模式匹配和可视化。 https://blog.csdn.net/intmainhhh/article/details/82557659

题目链接传送门

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 (2≤n≤1052≤n≤105) — the number of entrances.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤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

4
2 3 2 0

output

3

input

2
10 10

output

1

input

6 5 2 6 5 7 4

output

6

time limit per test

1 second

memory limit per test

256 megabytes

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<bits/stdc++.h>
const int maxn=1e5+10;
using namespace std;
int arr[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int lcount=0;
    int index=0;
    while((arr[index]-lcount)>0)
    {
        if(index==n-1)
            index=0;
        else
            index++;
        lcount++;
    }
    cout<<index+1<<endl;
}

代码2(思想差不多)

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int main()
{
    int i,n;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    int k=0;
    for(k=0;;k++)
    {
        for(i=1;i<=n;i++)
        {
            if(a[i]-n*k-i<0)
            {
                cout<<i<<endl;
                return 0;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/intmainhhh/article/details/82557659