uva10142(未ac)
来源:互联网 发布:天池大数据竞赛入门 编辑:程序博客网 时间:2024/05/17 04:36
#include <iostream>#include <stdio.h>#include <queue>#include <string.h>#include <vector>#include <sstream>#include <algorithm>using namespace std;vector<queue<int> > vote;int high,low;vector<string> namelist;int candidate[25];bool elimnate[25];int candidate_num;int cases;void init(){ memset(elimnate,false,sizeof(elimnate)); memset(candidate,0,sizeof(candidate)); vote.clear(); namelist.clear();}void read(){ cin>>candidate_num; string name; getline(cin, name); for(int i=0; i<candidate_num; i++) { getline(cin, name); namelist.push_back(name); } string ballot; getline(cin,ballot); while(ballot!="") { queue<int> q; stringstream ss(ballot); int id; while(ss>>id) { q.push(id); } vote.push_back(q); getline(cin,ballot); }}void compute(){ for(int i=0; i<vote.size(); i++) { int id=vote[i].front(); if(!elimnate[id-1]) candidate[id-1]++; } high=0; low=2000; for(int i=0; i<candidate_num; i++) { if(!elimnate[i]) { high=max(high,candidate[i]); low=min(low,candidate[i]); } } while(high>=low) { if(2*high>vote.size()) return ; for(int i=0; i<candidate_num; i++) if(candidate[i]==low) elimnate[i]=true; for(int i=0; i<vote.size(); i++) if(elimnate[vote[i].front()-1]) { while(elimnate[vote[i].front()-1]) vote[i].pop(); candidate[vote[i].front()-1]++; } high=0; low=2000; for(int i=0; i<candidate_num; i++) { if(!elimnate[i]) { high=max(high,candidate[i]); low=min(low,candidate[i]); } } }}void outresult(){ for(int i=0; i<candidate_num; i++) if(candidate[i]==high) cout<<namelist[i]<<endl;}int main(){ cin>>cases; int t=cases; while(cases--) { init(); read(); compute(); outresult(); cout<<t-cases<<endl; if(t!=cases) cout<<endl; } return 0;}
阅读全文
0 0
- uva10142(未ac)
- uva10142
- UVa1589(未ac)
- uva336(未ac)
- HDU 5035(未AC)
- half-consecutive(未AC)
- 未AC
- UVA 764 Pentominos(搜索)(未AC)
- [未AC]HDU1002
- HDU4069(未AC)
- 未AC 题
- 九度题目:简单计算器(1019)未AC
- 【POJ1061】:青蛙的故事(未AC版)
- POJ3664---没使用结构体,用数组(未AC)
- hdu 1051 Wooden Sticks(贪心未AC)
- 11.3-11.10未一次ac题目(2017)
- UVA10142/PC110108Australian Voting
- 福州oj 1689 未ac
- 理解时空涟漪引力波,只需看这个三个问题
- 干货|使用搜狗词库优化资源标签
- 那些美丽的图书馆们
- PHP程序员的技术成长规划
- 机器学习工程师最常用的十大算法
- uva10142(未ac)
- Shell---判断(if)和分支(case)
- 苹果拟在韩国开设首家直营店,攻入三星“大本营”
- Shell---for循环
- 什么是工程师文化?
- 机械键盘到底要不要买?秒懂!
- 干货|SourceInsight使用技巧之公共工程
- GitHub最流行语言:JS 还第一,Python 反超 Java
- 干货|使用luacov统计lua代码覆盖率