[uva-10142] Australian Voting (queue&vector)
2017-09-27 22:24
537 查看
今天下午到晚上才AC,
遇到了一些问题有:
1.runtime error 没有考虑只有一个候选人
2.compile error 没有加
3.WA的情况分别是
1)选票废掉之后选的还是淘汰的人
2)超过百分之五十写的>=…..
3)科科。必须按选号从小到大不能乱序搞TAT
4.系统一直报warning应该是还要把size转下int,不过我懒,警告就警告吧。
真的是很好的一道题你看
让我尝试了几乎所有的报错!
MMP
吃凉皮凉皮去了
何以解忧唯有暴饮暴食
遇到了一些问题有:
1.runtime error 没有考虑只有一个候选人
2.compile error 没有加
3.WA的情况分别是
1)选票废掉之后选的还是淘汰的人
2)超过百分之五十写的>=…..
3)科科。必须按选号从小到大不能乱序搞TAT
4.系统一直报warning应该是还要把size转下int,不过我懒,警告就警告吧。
真的是很好的一道题你看
让我尝试了几乎所有的报错!
MMP
吃凉皮凉皮去了
何以解忧唯有暴饮暴食
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <queue> #include <vector> #include <algorithm> using namespace std; struct candidate { string name; int votingnum; int tot; candidate(string a="",int b=0,int c=0) {name=a,votingnum=b,tot=c;} }; bool cmp(candidate A, candidate B) { if(A.tot!=B.tot) return A.tot<B.tot; return A.votingnum<B.votingnum; } vector < queue<int> > ballot; vector <candidate> Candi; vector <candidate> Out; int BallotTot,n; bool judge() { int siz=Candi.size(); int DeleTot; if(2*Candi[siz-1].tot>BallotTot) return true; DeleTot=Candi[0].tot; while(!Candi.empty()&&Candi[0].tot==DeleTot) { Out.push_back(Candi[0]); Candi.erase(Candi.begin()); } if(Candi.empty())return true; return false; } int main() { int t,i,j; bool flag=false; string input; cin>>t; while(t--) { cin>>n; getline(cin,input); Candi.clear(); ballot.clear(); ballot.resize(1100); Out.clear(); for(i=1;i<=n;i++) { getline(cin,input); Candi.push_back(candidate(input,i,0)); } BallotTot=0; while(getline(cin,input)) { if(input=="")break; int len=input.length(); int num=0; for(i=0;i<len;i++) { if(input[i]>='0'&&input[i]<='9') { num=num*10+(input[i]-'0'); if(i==len-1) ballot[BallotTot].push(num); } else { ballot[BallotTot].push(num); num=0; } }BallotTot++; } for(i=0;i<BallotTot;i++) { int x=ballot[i].front(); Candi[x-1].tot++; } sort(Candi.begin(),Candi.end(),cmp); while(!judge()) { while(!Out.empty()) { for(i=0;i<ballot.size();i++) { if(!ballot[i].empty()&&ballot[i].front()==Out[0].votingnum) { ballot[i].pop(); int x=ballot[i].front(); for(j=0;j<Candi.size();j++) { if(Candi[j].votingnum==x) { Candi[j].tot++;break; } //废掉的选票上变成了是淘汰的候选人 if(j==Candi.size()-1&&ballot[i].size()>1) { ballot[i].pop(); x=ballot[i].front(); j=-1; } } } }Out.erase(Out.begin()); }sort(Candi.begin(),Candi.end(),cmp); } int siz=Candi.size(); //空行 if(flag)cout<<endl; else flag=true; //输出 if(siz==0) { for(i=0;i<Out.size();i++) cout<<Out[i].name<<endl; } else { cout<<Candi[siz-1].name<<endl; } } return 0; }
相关文章推荐
- priority_queue<int,vector<int>,greater<int>>优先队列 按照由小到大顺序
- HDU 1387 && UVa 540 Team Queue(队列应用)
- <stack>,<queue>,<vector>的用法
- priority_queue<int,vector<int>,greater<int>>优先队列 按照由小到大顺序
- UVa 540 Team Queue (STL list&queue模拟插队)
- Ugly Numbers(set,queue,vector) -uva 136
- 【STL】 poj1208&&UVa101 The Blocks Problem (不定长数组vector的应用)
- 紫书章五例题9 数据库 UVA 1592 (map+vector)
- uva 1086 - The Ministers' Major Mess(TwoSat)
- ACM->uva401
- UVA 10277 Boastin' Red Socks
- [UVA11922] Permutation Transformer && Splay模板
- uva 540 Team Queue
- STL源码解析-04序列容器-05heep&priority_queue
- UVa 120 Stacks of Flapjacks (STL deque&reverse)
- UVa Live Archive 3971 & UVa 12124 & POJ 3497 - Assemble
- NSArray和 Vector<struct>互转
- UVALive 5871 Arnooks's Defensive Line (cdq分治)
- 【动态规划】[UVa 11825]Hackers' Crackdown
- UVA - 540 - Team Queue