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≤10^5) — the number of entrances.
The second line contains nn integers a1,a2,…,an (0≤ai≤10^9) — 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个数,每个数单位时间内减1,求到达位置上为0的位置,刚开始做的时候想模拟一下,但是有些麻烦,后来找到一个规律,假设循环k次找到这个值,那么k*n+i==a[i],找出其中最先出现的最小a[i]值,其i即为所求。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#include<list>
#include<algorithm>
#include <ctime>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) (a=a+b,b=a-b,a=a-b)
#define memset(a,v) memset(a,v,sizeof(a))
#define X (sqrt(5)+1)/2.0
#define maxn 320007
#define N 200005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define mod 1000000009
#define e 2.718281828459045
#define eps 1.0e-8
#define ll long long
using namespace std;
ll a[222222],t[222222];
int main()
{
int n;
cin>>n;
for(int i=0; i<n; i++)
cin>>a[i];
for(int i=0;i<n;i++)
{
if(a[i]<=i)
continue;
t[i]=(a[i]-i)/n;
if(t[i]*n+i<a[i])
t[i]++;
}
int min1=INF,flag=0;
for(int i=0;i<n;i++)
if(t[i]<min1)
{
min1=t[i];
flag=i;
}
cout<<flag+1<<endl;
return 0;
}