题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
题目3 : Spring Outing
描述
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>
#include <cstring>
#include <cstdio>
#define lowbit(x) (x&(-x))
using namespace std; int map[1005][1005]; int n,k,t; int main(){ while(scanf("%d%d",&n,&k)!=EOF){
for(int i=1;i<=n;i++){
for(int j=1;j<=k+1;j++){
scanf("%d",&t);
map[i][t]=j;
}
}
int ans=0;
for(int j=k;j>=1;j--){
int cnt=0;
for(int i=1;i<=n;i++){
if(map[i][j]<map[i][ans])
cnt++;
}
if(cnt>n/2)
ans=j;
}
if(ans>0)
printf("%d\n",ans);
else printf("otaku\n"); }
return 0;
}
题目3 : Spring Outing 微软2016校园招聘在线笔试第二场的更多相关文章
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- 微软2016校园招聘在线笔试-Professor Q's Software
题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...
- 微软2016校园招聘在线笔试 [Recruitment]
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A company plans to recruit some new employees. There are N ca ...
- 微软2016校园招聘在线笔试之Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- 微软2016校园招聘4月在线笔试 A FontSize
题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...
- 微软2016校园招聘4月在线笔试 ABC
题目链接:http://hihocoder.com/contest/mstest2016april1/problems 第一题:输入N,P,W,H,代表有N段文字,每段有ai个字,每行有⌊W/S⌋个字 ...
- 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...
- hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)
hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...
随机推荐
- python之set集合及深浅拷贝
一.知识点补充 1.1字符串的基本操作 li =["李李嘉诚", "麻花藤", "⻩黄海海峰", "刘嘉玲"] s = ...
- ACM_百度的面试(单调栈)
百度的面试 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在一个二维平面,从左到右竖立n根高度分别为:a[1],a[2],... ...
- ios TextField 不被键盘遮住
首先放一个scrollView窗口,将Scroll View视图占整个屏幕. 向Scroll View 添加TextField 控件. 首先,ViewController.h 代码如下; #i ...
- [转]mysql视图学习总结
转自:http://www.cnblogs.com/wangtao_20/archive/2011/02/24/1964276.html 一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个 ...
- CSS——dispaly、overflow、visibility、opacity
隐藏盒子: 1.overflow:hidden; 隐藏盒子超出的部分. 2.display: none; 隐藏盒子,而且不占位置.(用的最 ...
- C#——简单工厂
简单工厂的方法实现过程核心就是之前介绍的接口应用.所以直接上代码: public interface IPerson { void Say(); } public class Student : IP ...
- js 学习笔记---基本概念
早已接触javascript多年之后,竟然还有这些概念混淆不清,毫不知情,说出来真实无地自容 ! 1.使用严格模式,"use strict",虽然不适用,但是要知道,以免别人使用时 ...
- Java_Web三大框架之Hibernate 入门(一)
一.Hibernate简介: Hibernate作者——Gavin King Hibernate创始人 < Hibernate in action >作者 EJB 3.0的Entity b ...
- Shell基本运算符
原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用. expr 是一款表达式计算工具,使用它能完成表达式的求值操作. 例如,两个数相加(注意使用 ...
- PHP 之文件锁解决并发问题
一.参数说明 $handle: 文件资源 $operation: 锁的类型 LOCK_SH: 共享锁 LOCK_EX: 排他锁 LOCK_UN: 释放锁 $wouldblock: 设置为true的时候 ...