URAL 1794 Masterpieces of World Architecture
2015-04-27 23:56
302 查看
题意:有n个学生,要轮着发言,每个学生都有自己所想的发言顺序,问尽量使大家满意,求第一个发言的人的序号。
题解:这题有很巧妙的做法,维护一个b[i] = j,表示序号为i的学生作为第一发言人得到j个人支持。当某个学生得到自己想要的发言顺序的时候,就可以知道这情况下第一个发言的人的序号,也就是这种情况下他支持谁先发言,统计所有人作为第一发言人的被支持次数。最后求出作为第一发言人被支持最多的序号就是答案。
题解:这题有很巧妙的做法,维护一个b[i] = j,表示序号为i的学生作为第一发言人得到j个人支持。当某个学生得到自己想要的发言顺序的时候,就可以知道这情况下第一个发言的人的序号,也就是这种情况下他支持谁先发言,统计所有人作为第一发言人的被支持次数。最后求出作为第一发言人被支持最多的序号就是答案。
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int a[100100],b[100100]; int main() { int n; scanf("%d",&n); memset(b,0,sizeof(b)); for(int i = 1; i <= n; i++) { scanf("%d",&a[i]); b[(n + i - a[i])%n + 1]++; } int ans = 1; int maxn = b[1]; for(int i = 2; i <= n; i++) { if(b[i] > maxn) { ans = i; maxn = b[i]; } } printf("%d\n",ans); return 0; }
相关文章推荐
- URAL - 1794 Masterpieces of World Architecture(“投票法”)
- [CFNews] Be first to get Oxygen Forensic Suite 5.0 just before the End of the World!
- Building Block of Enterprise Architecture
- 每日英语:The End Of The World Is (Not) Nigh
- 1 Hello, world of concurrency in C++!
- Instances Based on Opencv2: A Simple Analysis of MVC Architecture
- Ural 1658 Sum of Digits
- HDU 4596 Yet another end of the world(GCD)
- If the World Were a Village of 100 People
- story of the world
- Hello World of OpenCascade
- URAL 1735 Theft of the Century
- URAL 1057 Amount of Degrees 数位DP *
- 读 Patterns of Enterprise Application Architecture 1
- 号外:物理构建类解谜游戏World of Goo下载
- Mining the Link Structure of the World Wide Web
- 【Hello Python World】Class Notes of Week 5
- The Architecture Of Avalon
- enter the world of net working programming , and be a expect of it
- world's highest standard of living