码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-21 09:44:37      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

 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

input output
4
4 1 2 3
2
3
1 1 1
3

比赛时是队友写出来的,思路就是对每个人求满足其位置需求的排列第一个演讲的是谁,累加后“得票”最多的既为第一个演讲的人。

有个大神题解写的很明白,贴个链接

http://blog.csdn.net/pegasuswang_/article/details/10414563

#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;
}



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

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45161105

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!