传送门

#1154 : Spring Outing

时间限制: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 \le N, K \le 10$

For 100% of the data, $1 \le N, K \le 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

Analysis:

这道题出自微软2016校园招聘在线笔试第二场首先要明确题意。这道题像是一道博弈论问题(有“纳什均衡的即视感”--某君语),并且确是一道博弈论问题。但没有博弈论的知识也可以入手分析。


我最初的思路也不是正解,赛后讨论区有人询问思路,答曰“倒推”。我想了一周左右,中间还和同学讨论了一次,才明白如何倒推(愚钝如我者)。


假设投票进行到了最后一轮(表决第K个也是最后一个地点)。此轮投票前,众人都知道(每个人都足够聪明)结果只有两种:去第K个地点 or 呆在家。此时,显然地,每个人都将投更想去的地方。将要进行第K轮投票时,大家已经知道最后结果了。因此事实上第K轮投票是没必要的。


假设第K轮投票结果是R(K),R(K)=0或K,那么第K-1轮投票的结果是K-1或R(K),或者说第K-1轮投票实际上是众人在第K-1和R(K)之间选择,因而结果R(K-1)也是预先知道的,第K-1轮投票也没必要。

按此思路可推知R(1),这就是答案。


我们看到在本题中,无需投票众人就知到最后结果了,当然这是由于投票前preference list已成为common knowledge,在实际中这往往是不可能的。


Impelementation:

代码不难写,复杂度是O(N*K),已是读入复杂度了,也没有优化的必要。


#include<bits/stdc++.h>
#define X first
#define Y second
#define MP make_pair
using namespace std;
const int MAX_N=1e3+, MAX_K=1e3+;
int pref[MAX_N][MAX_K];
typedef pair<int, int> pii;
int N, K;
bool cmp(const int &x, const int &y){
int a=x%(K+), b=y%(K+);
int cnt1=, cnt2=;
for(int i=; i<N; i++){
pref[i][a]<pref[i][b]?cnt1++:cnt2++;
}
return cnt1==cnt2?x>y:cnt1>cnt2;
}
int main(){
//freopen("in", "r", stdin);
int place;
scanf("%d%d", &N, &K);
for(int i=; i<N; i++){
for(int j=; j<=K; j++){
scanf("%d", &place);
pref[i][place]=j;
}
}
int last=K+, pre=K;
while(pre){
if(cmp(last, pre)) --pre;
else last=pre, --pre;
//printf("%d %d\n", pre, last);
}
last==K+?puts("otaku"):printf("%d\n", last);
return ;
}
												

hihocoder 1154 Spring Outing的更多相关文章

  1. 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场

    题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...

  2. BNUOJ-29358 Come to a spring outing 搜索,DP

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29358 状态虽然很多,但是非常稀疏,dfs搜索然后剪下枝.. 或者DP,f[i][j][k ...

  3. Meeloun教你如何正式切入Essay写作话题

    很多同学在Essay写作过程中会发现:如果题目问到解决办法,写来写去,都是政府要颁布政策,人们要提高意识,感觉一点新意也没有.怎么样更好地切合不同的话题,想到最合适的解决办法呢?今天小编为你奉上更多处 ...

  4. 2018 Spring Single Training B (uva 572,HihoCoder 1632,POJ 2387,POJ 2236,UVA 10054,HDU 2141)

    这场比赛可以说是灰常的水了,涨信心场?? 今下午义务劳动,去拿着锄头发了将近一小时呆,发现自己实在是干不了什么,就跑到实验室打比赛了~ 之前的比赛补题补了这么久连一场完整的都没补完,结果这场比完后一小 ...

  5. spring如何解决单例循环依赖问题?

    更多文章点击--spring源码分析系列 1.spring循环依赖场景2.循环依赖解决方式: 三级缓存 1.spring循环引用场景 循环依赖的产生可能有很多种情况,例如: A的构造方法中依赖了B的实 ...

  6. Spring filter和拦截器(Interceptor)的区别和执行顺序

    转载自:http://listenup.iteye.com/blog/1559553 1.Filter过滤器只过滤jsp文件不过滤action请求解决方案 解决办法:在web.xml中将filter的 ...

  7. Spring框架中文件目录遍历漏洞 Directory traversal in Spring framework

    官方给出的描述是Spring框架中报告了一个与静态资源处理相关的目录遍历漏洞.某些URL在使用前未正确加密,使得攻击者能够获取文件系统上的任何文件,这些文件也可用于运行SpringWeb应用程序的进程 ...

  8. 基于spring注解AOP的异常处理

    一.前言 项目刚刚开发的时候,并没有做好充足的准备.开发到一定程度的时候才会想到还有一些问题没有解决.就比如今天我要说的一个问题:异常的处理.写程序的时候一般都会通过try...catch...fin ...

  9. 玩转spring boot——快速开始

    开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...

随机推荐

  1. 原生js实现增加(addclass),删除(removeclass),判断是否存在(hasclass),如果存在删除,如果不存在添加(toggleclass)和获取类名(getbyclass)的方法

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. (转载)java多态(2)-------Java转型(向上或向下转型)

    5.13.1 向上转型 我们在现实中常常这样说:这个人会唱歌.在这里,我们并不关心这个人是黑人还是白人,是成人还是小孩,也就是说我们更倾向于使用抽象概念“人”.再例如,麻雀是鸟类的一种(鸟类的子类), ...

  3. 设置linux账号的有效时间

    在linux系统中,默认创建的用户的有效期限都是永久的,但有时候,我们需要对某些用户的有效期限做个限定!比如:公司给客户开的ftp账号,用于客户下载新闻稿件的.这个账号是有时间限制的,因为是付费的.合 ...

  4. PHP mcrypt加密扩展使用总结

    在开发中,很多时候我们在前后端交互中需要对一些敏感数据进行一定的加密.PHP中有提供了mcrypt的这样一个加密扩展实现对数据的加密解密. 一.mcrypt扩展的安装 在低版本的PHP中需要在配置文件 ...

  5. 【转】【WPF】WriteableBitmap应用及图片数据格式转换

    使用 WriteableBitmap 类基于每个框架来更新和呈现位图.这对于生成算法内容(如分形图像)和数据可视化(如音乐可视化工具)很有用. WriteableBitmap 类使用两个缓冲区.“后台 ...

  6. Navi.Soft20.WinCE使用手册

    1.概述 1.1应用场景 随着物联网的普及,越来越多的制造商对货品从原料配备,加工生产,销售出库等环节的要求和把控越来越高.在此情况之下,传统的ERP软件已经无法满足现有的流程. 移动设备的应用,在很 ...

  7. [资料]Nginx做IP访问限制以及正则规则

    nginx配置location总结及rewrite规则写法 Nginx Location配置总结 Nginx 禁止某个IP访问 server { listen 443; root /webroot/; ...

  8. vue2.0入门

    vue2.0 开发实践总结之入门篇   vue2.0 据说也出了很久了,博主终于操了一次实刀. 整体项目采用  vue +  vue-router +  vuex (传说中的vue 全家桶 ),构建工 ...

  9. listview向下滑动过程中背景色变成黑色和一些奇怪问题

    ListView是一个经常要用到的android控件,现总结遇到过的一些美化的小细节. 1.listview在拖动的时候背景图片消失变成黑色背景,等到拖动完毕我们自己的背景图片才显示出来 这个问题是我 ...

  10. matlab数据转换为字符串并合并字符串标注到图像曲线上

    1.把数字转换为字符串 [函数描述]str=num2str(A):把数组A中元素取小数点后四位,并转换为字符串. [函数实例]把数字转换为字符串,输入语句: str1=num2str(pi) str2 ...