Spring Outing
来源:互联网 发布:mac上的输入法 编辑:程序博客网 时间:2024/05/22 08:04
时间限制:20000ms
单点时限:1000ms
内存限制:256MB
描述
You class are planning for a spring outing. N people are voting for a destination out of K candidate places.
The voting progress is below:
First the class vote for the first candidate place. If more than half of the class agreed on the place, the place is selected. The voting ends.
Otherwise they vote for the second candidate place. If more than half of the class agreed on the place, the place is selected. The voting ends.
Otherwise they vote for the third candidate place in the same way and go on.
If no place is selected at last there will be no spring outing and everybody stays at home.
Before the voting, the Chief Entertainment Officer did a survey, found out every one’s preference which can be represented as a permutation of 0, 1, … K. (0 is for staying at home.) For example, when K=3, preference “1, 0, 2, 3” means that the first place is his first choice, staying at home is the second choice, the second place is the third choice and the third place is the last choice.
The Chief Entertainment Officer sends the survey results to the class. So everybody knows the others’ preferences. Everybody wants his more prefered place to be selected. And they are very smart, they always choose the optimal strategy in the voting progress to achieve his goal.
Can you predict which place will be selected?
输入
The first line contains two integers, N and K, the number of people in your class and the number of candidate places.
The next N lines each contain a permutation of 0~K, representing someone’s preference.
For 40% of the data, 1 <= N, K <= 10
For 100% of the data, 1 <= N, K <= 1000
输出
Output the selected place. Or “otaku” without quotes if no place is selected.
样例提示
In the sample case, if the second peoson vote against the first place, no place would be selected finally because the first person must vote against the second place for his own interest. Considering staying at home is a worse choice than the first place, the second person’s optimal strategy is voting for the first place. So the first place will be selected.
样例输入
2 2
1 0 2
2 1 0
样例输出
1
#include "iostream"using namespace std;int N, K; //N个人,K个地点int ranks[1000][1001]; //ranks[j][i]表示第j个人心中,地点i的排名,值越小越靠前int solve(){ int vote, result = 0; int i, j; for(i=K; i>=1; i--) { vote = 0; for(j=0; j<N; j++) if(ranks[j][i] < ranks[j][result]) vote++; if(vote > N/2) result = i; } return result;}int main(){ cin >> N >> K; int i, j, r; for(i=0; i<N; i++) { for(j=0; j<=K; j++) { cin >> r; ranks[i][r] = j; } } int result = solve(); if(result > 0) cout << result; else cout << "otaku"; return 0;}
- Spring Outing
- Spring Outing
- Spring Outing 解题报告
- 【ACM】Spring Outing
- #1154 :Spring Outing
- HDU 1707 Spring-outing Decision
- 微软笔试题《Spring Outing》
- Outing
- Problem 1463 - Come to a spring outing
- hihocoder week 86 Spring Outing【思维】
- WHU1463(Come to a spring outing)背包问题-DP
- Spring Outing 微软2016校园招聘在线笔试第二场
- 工场outing
- 【模拟题,未知算法】hdu hdoj 1761 Spring-outing Decision(2)
- HDU 1707 Spring-outing Decision(输出课程表是否与假期冲突)
- CSU1580: Outing(图论+DP)
- Candy 出去玩 (outing)
- CSU1580: Outing(强连通+拓扑排序+dp)
- oracle之子查询常用
- 2016太原UI设计师让你快速学会UI界面设计及网页设计的配色技巧
- return 语句
- HP大中华区总裁孙振耀退休感言
- 我的百分比数据盘(样式优美)
- Spring Outing
- Javascript常用正则表达式以及JS常见正则表达式笔试题
- [笔记][unity]Runtime(运行时)将Texture转到Sprite
- 版本控制器SVN与Git
- uva 11427
- viewport
- iOS NSNotificationCenter 使用姿势详解
- iOS多线程编程的定义及方法
- Android开发学习笔记:浅谈WebView