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 (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

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

题解:这个题是一个模拟题,问有n个队伍,你不想排队,每次只能走到下一个队伍

请问你在哪个队伍可以不用排队

首先我们可以想到,第一遍走的情况,从头到尾,

那么第一遍模拟就可以是   for(int i =0 ;i<n;i++) a[i]-=i;

这里就有问题了 如果第一遍走不完怎么办 继续从最后一个走到第一个 ,这是一个类似于环一样的

可是我们第一遍模拟的时候只考虑了走后面的情况,走过前面的需要还原,所以我们这里倒着减一下,

使得走一遍后保证每个队伍都走了n个单位长度

那么这里有问题了  如果n特别小但是a[i]特别大呢

我们有两个优化的地方

1.找出a[i]的最小值,每个都减去min

2.由于a[i]<1e9,n<=1e5,那么在n的循环里面循环20次就可以满足至少出现一个空队列的情况

代码如下

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn= 1e5+;
const int INF = 0x3f3f3f3f;
ll a[maxn];
int main() {
int n;
while(~scanf("%d",&n)) {
int ans=;
int minn=INF;
for(int i=; i<n; i++) {
scanf("%lld",&a[i]);
if(a[i]<minn) minn=a[i];
}
int cnt=minn/n;
//优化1
for(int i=; i<n ; i++) {
a[i]-=cnt*n;
}
//优化2
for(int d=; d<=; d++) {
for(int i=; i<n; i++) {
a[i]-=i;
if(a[i]<=) {
cout<<i+<<endl;
return ;
}
}
//还原
for(int i=n-;i>=;i--) {
a[i] -= n - i;
}
}
}
return ;
}

code forces 996BWorld Cup的更多相关文章

  1. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  2. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  3. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  4. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  5. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  6. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  7. code forces Watermelon

    /* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...

  8. code forces Jeff and Periods

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

  9. Code Forces Gym 100971D Laying Cables(单调栈)

    D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. input属性总结

    <input type="text" readonly="readonly" /> 这个是不能输入的 readonly="readonly ...

  2. python--Pandas(一)

    一.Pandas简介 1.Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一 ...

  3. c# .net 3.5 4.0 4.5 5.0 6.0各个版本新特性战略规划总结【转载】

    引用:http://blog.csdn.net/attilax/article/details/42014327 c# .net 3.5 4.0 各个版本新特性战略规划总结 1. ---------- ...

  4. HTML常用标签用法及实例

    HTML常用标签用法及实例1.<!--1.注释-->2.<!--2.DOCTPYE 声明文档类型-->3.<!--3.a--> <a href="h ...

  5. yii2邮箱发送

    yii2 邮件发送  163邮箱 1.在配置文件main-local.php components=>[]里面配置 'mailer' => [ 'class' => 'yii\swi ...

  6. python中函数的不定长参数

    例1: #定义一个含有不定长参数的函数,本例第三个参数*args def sum_nums(a,b,*args): print('_'*30) print(a) print(b) print(args ...

  7. iar注释快捷键

    选中多行后注释快捷键:Ctrl+K 取消多行注释快捷键:Ctrl+Shift+K

  8. TouTiao开源项目 分析笔记16 新闻评论

    1.要达到的效果 1.1.主要效果图 点击了标题栏的消息图标后,然后会跳转到评论详情的页面. 1.2.触发的点击事件 在新闻详情的片段中的菜单点击事件中 设置上方标题栏的消息标的监听事件 case R ...

  9. 15.2,redis发布订阅

    发布publish 订阅subscribe Redis 通过 PUBLISH . SUBSCRIBE 等命令实现了订阅与发布模式. 举例1: qq群的公告,单个发布者,多个收听者 发布/订阅 实验 发 ...

  10. 第四模块:网络编程进阶&数据库开发 练习

    练习题 基于queue模块实现线程池 import threading from multiprocessing import Queue class A(threading.Thread): def ...