World Cup CodeForces - 996B 思维(推公式)

B. World Cup
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Allen wants to enter a fan zone that occupies a round square and has n entrances.

There already is a queue of ai people in front of the i-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 n (2≤n≤105) — the number of entrances.

The second line contains n integers a1,a2,…,an (0≤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
inputCopy
4
2 3 2 0
outputCopy
3
inputCopy
2
10 10
outputCopy
1
inputCopy
6
5 2 6 5 7 4
outputCopy
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]. 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].

题意:给出一个序列,表示第i扇门有i个人在排队,每扇门每次只允许一个人进入。刚开始这个Alles 站在第一扇门后面,每分钟,如果他在这一分钟内不被允许进入球迷区(这意味着他不是排队的第一个),他就会离开当前的队伍,站在下一个入口(或者如果他离开最后一个入口,则是第一个入口)的队伍的末尾。 问最快能从哪个门出来,输出门的位置即可。

分析:
我们可以知道,第k扇门的人数为b[k],那么如果要Alles出来,必须当前门的人都走完,所以说,第t轮,k+tn 表示第t轮的时间,那么,此时的时间一定要比b[k]大,为什么呢,你得先等b[k]的人走完,你才能走吧,所以要比b[k]大。综上所述,b[k]=k+tn 所以只要求出最小的t的k轮就是答案。

代码中的int t=b-i+n; 至于为什么要+n,防止负数。

AC代码:

#include <bits/stdc++.h>
#define INF (1<<30)
using namespace std;
int n,b;
int main()
{
	scanf("%d",&n);
	int minn=INF;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b);
		int t=b-i+n;
		if(t/n<minn)
		{
			minn=t/n;
			ans=i;
		}
	}
	printf("%d\n",ans);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值