您的位置:首页 > 其它

URAL - 1794 Masterpieces of World Architecture(“投票法”)

2015-04-21 01:07 302 查看
Masterpieces of World Architecture

Time Limit: 1000MSMemory Limit: 65536KB64bit IO Format: %I64d & %I64u
Submit Status

Description

Maria Ivanovna informed all of her fifth-graders that in a month they would have a class on the topic “Masterpieces of World Architecture.” Each of the students had to prepare a short report about a famous architectural structure.
As always, the best students prepared their reports in advance and the worst students started preparing for the class only several minutes before it.

The class has begun. According to the tradition, at such classes the children are sitting in a circle and speaking one after another in clockwise order. The best students like to be the first to speak, while the worst students
want to be the last because they are trying to finish their reports right during the class.

Maria Ivanovna has asked each student which in turn they want to present their reports. Now she has to decide who will be the first to speak so that as many children as possible will have their turn to speak exactly as they want.

Input

The first line contains the number n of students in the class (2 ≤ n ≤ 10 5). Maria Ivanovna has numbered all the children from 1 to nclockwise
in the order in which they are sitting. The second line contains integers a1, …, an (1 ≤ ai ≤ n) separated with
a space, where ai is the number told by the ith student.

Output

Output the number of the student who should start the class “Masterpieces of World Architecture” by presenting their report. If there are several possible answers, output any of them.

Sample Input

inputoutput
4
4 1 2 3

2

3
1 1 1

3

比赛时是队友写出来的,思路就是对每个人求满足其位置需求的排列第一个演讲的是谁,累加后“得票”最多的既为第一个演讲的人。
有个大神题解写的很明白,贴个链接
/article/1512883.html

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<utility>
#define inf 0x3f3f3f3f
#define eps 1e-6
int a[100010];
int cnt[100010];
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d",a+i);
		}
		memset(cnt,0,sizeof(cnt));
		for(int i=0;i<n;i++)
		{
			cnt[(i+n+1-a[i])%n]++;
		}
		int max=0;
		int pos;
		for(int i=0;i<n;i++)
		{
			if(cnt[i]>max)
			{
				max=cnt[i];
				pos=i+1;
			}
		}
		cout<<pos<<endl;
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: