URAL - 1794 Masterpieces of World Architecture(“投票法”)
2015-04-21 01:07
302 查看
Masterpieces of World Architecture
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
比赛时是队友写出来的,思路就是对每个人求满足其位置需求的排列第一个演讲的是谁,累加后“得票”最多的既为第一个演讲的人。
有个大神题解写的很明白,贴个链接
/article/1512883.html
Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
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 |
有个大神题解写的很明白,贴个链接
/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; }
相关文章推荐
- URAL 1794 Masterpieces of World Architecture
- 第一章 概述 Summarization of Search Engine Architecture
- is-there-common-street-addresses-database-design-for-all-addresses-of-the-world
- The Architecture of Open Source Applications: Asterisk
- Architecture of a Highly Scalable NIO-Based Server
- HDU 4596 Yet another end of the world (数学,扩展欧几里德)
- URAL 1732 Ministry of Truth KMP
- Challenges and solutions - Architecture of a Modern Web Application
- Ural 1057 Amount of Degrees(数位DP)
- Visual Studio warning MSB3270:There was a mismatch between the processor architecture of the project being built "MSIL"
- Note of big data dummies:Big data management architecture
- Ural 2045 Richness of words(构造)
- helloworld program of Linden Scripting Language
- URAL 1014 Product of Digits
- ural 2017 Best of a bad lot
- Architecture of Windows Workflow Foundation
- URAL 1613 For Fans of Statistics
- An Empirical Study of Real-world Polymorphic Code Injection Attacks
- R自动数据收集第一章概述——《List of World Heritage in Danger》
- Ural 1014-The Product of Digits