World Cup ( Codeforces 996B )

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lxt_Lucia/article/details/81557980

欢迎访问 https://blog.csdn.net/lxt_Lucia ~~

宇宙第一小仙女 \ ( ^ o ^ ) / ~ ~萌量爆表求带飞 =≡Σ((( つ^o^)つ ~ dalao们点个关注呗~ 

World Cup ( Codeforces 996B ) 

Description

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.

Sample Input

Input

4
2 3 2 0

Output

3

Input

2
10 10

Output

1

Input

6
5 2 6 5 7 4

Output

6

Hint

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] 。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] 。

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] 。

题意:

说的形象一点叭~

可以看成餐厅有 n 个窗口,每个窗口都有相对应的人在排队买饭,而你会按顺序 ( 从第一个窗口出发 ) ,在每个窗口等一分钟,若该窗口人数为 0 ,则在该窗口买饭,否则就移步下一个窗口,若排完最后一个窗口还未买到饭,则回到第一个窗口继续排。

注意:

1)每个人打一次饭都要一分钟,所以每过一分钟所有窗口的人数都会一起减 1 。

2)不能插队,即每次都只能排在队尾。

3)不能跳窗口,即只能按顺序到下一个窗口。

4)只有到 0 的时候才可以买饭,假设第一个窗口是1,则不能买,因为这一分钟是你前面的那个人买饭,所以你就会跳到第二个窗口。

思路:

思维题,直接算出走了几轮,选轮数最小的,若轮数相同就选最先出现的,就阔以啦~

由题意每轮有 n 个窗口,则轮数为( a - i ) / n ,为防止轮数出现负数不便于计算,就再加上一个 n ,因为所有的都加了 n ,就等于集体把轮数加了 1 ,所以并不会影响最终的结果。( a - i + n ) / n < min1 时才讲原坐标覆盖,相等时不覆盖,这样可以就保证选到的是最先出现的啦~

代码:

#include<cstdio>
int main()
{
    int n,ans;
    long long int a,min1=0x3f3f3f3f;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&a);
        if((a-i+n)/n<min1)
        {
            min1=(a-i+n)/n;
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}

欢迎访问 https://blog.csdn.net/lxt_Lucia ~ ~

宇宙第一小仙女 \ ( ^ o ^ ) / ~~萌量爆表求带飞 =≡Σ((( つ^o^)つ ~

dalao们随手点个关注呗 ~ 

猜你喜欢

转载自blog.csdn.net/lxt_Lucia/article/details/81557980
今日推荐