hihocoder week 86 Spring Outing【思维】
来源:互联网 发布:搜狗手机输入法mac 编辑:程序博客网 时间:2024/06/05 17:14
P1 : Spring Outing
- Sample Input
2 21 0 22 1 0
- Sample Output
1
Description
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?
Input
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
Output the selected place. Or "otaku" without quotes if no place is selected.
Hint
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.
思路:考虑最后一轮投票,投反对票的人一定认为0比m好,投赞成票的一定认为m比0好。而对于个人而言,0和m好不好在于它们在自己心目中的排名。这样的话对于给定的信息,可以确定最后一轮投票的结果。继续向下推,会发现第i-1轮投票可以唯一确实第i轮投票结果。于是我们可以从第m轮结果开始向前推,发现有更靠前的地点满足就更新。
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <string>using namespace std;typedef long long LL;const int MAXN = 1005;const int INF = 0x3f3f3f3f;int id[MAXN][MAXN];int main(){ int n, m; while(scanf("%d%d", &n, &m) != EOF) { for(int i = 1; i <= n; i++) { for(int j = 0; j <= m; j++) { int v; scanf("%d", &v); id[i][v] = j; } } int ans = 0; for(int i = m; i >= 1; i--) { int cnt = 0; for(int j = 1; j <= n; j++) if(id[j][ans] > id[j][i]) cnt++; if(cnt > n / 2) ans = i; } printf(ans ? "%d\n" : "otaku\n", ans); } return 0;}
- hihocoder week 86 Spring Outing【思维】
- Spring Outing
- Spring Outing
- Spring Outing 解题报告
- 【ACM】Spring Outing
- #1154 :Spring Outing
- HDU 1707 Spring-outing Decision
- 微软笔试题《Spring Outing》
- Outing
- hihoCoder week 80
- Problem 1463 - Come to a spring outing
- HihoCoder-1523(思维)
- (简单思维)HihoCoder
- hihoCoder week 84 P1 : Lucky Substrings 【dp】
- hihoCoder week 85 Numeric Keypad 【DFS】
- hihoCoder 92week Miller-Rabin质数测试
- HihoCoder 93week Eular质数筛法
- WHU1463(Come to a spring outing)背包问题-DP
- Activity生命周期
- 设计模式大全
- JSON 之GSON 解析
- Item (Mage_Catalog_Model_Product) with the same id ”xxx“ already exist
- 【转】史上最全的CSS hack方式一览
- hihocoder week 86 Spring Outing【思维】
- 23种设计模式
- mysql优化之thread_cache_size
- JDK5新特性之泛型
- 传入输入流即可将流中的数据转成String
- 当存放表决盘的磁盘组发生磁盘丢失时,启动CRS的步骤 (文档 ID 2055530.1)
- 鸡兔同笼代码
- magento log问题
- OCR/Vote disk 维护操作: (添加/删除/替换/移动) (文档 ID 1674859.1)转到底部转到底部