zoukankan      html  css  js  c++  java
  • CodeForces

    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
    4
    2 3 2 0
    Output
    3
    Input
    2
    10 10
    Output
    1
    Input
    6
    5 2 6 5 7 4
    Output
    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].

      第一秒的时候这个人站在第一个数上,这个人每秒钟向前移动一步,每移动一步区间中的所有的数都会减一,直到他恰好走到一个数减为零的地方,输出该位置的序号。

      显而易见。只是一个循环,周期已知,步长已知,故而可推算出每个数在第几圈的时候减为零 nk*(i-1)==Ai (n是序列的长的,k是最少需要的圈数,i是位置的序列,Ai是第i个数的值) ,k最小的那个位置即为答案。

      

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<string>
     5 #include<cmath>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<stack>
     9 #include<deque>
    10 #include<map>
    11 #include<iostream>
    12 using namespace std;
    13 typedef long long  LL;
    14 const double pi=acos(-1.0);
    15 const double e=exp(1);
    16 const int N = 10;
    17 
    18 LL con[100009];
    19 int main()
    20 {
    21     LL i,p,j,n;
    22     LL mid;
    23     scanf("%lld",&n);
    24     for(i=0;i<n;i++)
    25     {
    26         scanf("%lld",&con[i]);
    27         mid=ceil((double)(con[i]-i)/n);
    28         con[i]=mid;
    29     }
    30     LL head=999999999999,spot=1;
    31     for(i=0;i<n;i++)
    32     {
    33         if(con[i]<head)
    34         {
    35             head=con[i];
    36             spot=i+1;
    37         }
    38     }
    39     printf("%lld
    ",spot);
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    集合赋值及for循环删除符合条件的元素
    shiro系列12:rememberme(记住我)
    shiro系列11:缓存
    shiro系列10:会话管理
    shiro系列8:授权源码解析
    shiro系列7:拦截器
    shiro系列6:授权
    shiro系列5:Realm
    shiro系列4:认证源码解析
    shiro系列3:MD5盐值加密认证流程
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9694777.html
Copyright © 2011-2022 走看看