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?


IDEA

i表示第i个人,从0->n-1;

p表示第p个地方,从1->k,0表示那都不选

prefer[i][p]表示表示在i心中选择p的排位为j,j从0->k

从j=k开始到1,若果出现选择人数大于总人数一般的,则标记place为该地方


CODE

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif 
	int n,k;
	while(cin>>n>>k){	
		vector<vector<int> > prefer;
		prefer.resize(n,vector<int> (k+1));
		for(int i=0;i<n;i++){
			for(int j=0;j<k+1;j++){
				int p; cin>>p;
				prefer[i][p]=j;
			}
		}
		int place=0;
		for(int j=k;j>=1;j--){
			int cnt=0;
			for(int i=0;i<n;i++){
				if(prefer[i][j]<prefer[i][place]){
					cnt++;
				}
			}
			if(cnt>n/2){
				place=j;
			}
		}
		if(place==0){
			cout<<"otaku"<<endl;
		}else{
			cout<<place<<endl;
		}		
	}
	return 0;
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值