Codeforces 749C Voting 贪心+模拟
来源:互联网 发布:软件开发项目决算书 编辑:程序博客网 时间:2024/04/29 14:23
点击打开链接
题意:有两组人D和R,一次轮流投票,D的人可以说R里面的某个人不能投,也可以什么都不做,R里面的同理
//贪心:轮到第i人(D)投票时,应选择把下一个能做决策的对手X(R)淘汰(既淘汰掉一个人,又防止下一个D被淘汰,即可能又多了一次淘汰(R)的机会)
//RDRDDRD ->RDD->D Win:D
//用队列模拟即可
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;const int inf=1e9;const int N=2e5+20;char s[N];int main(){int n;while(cin>>n){queue<int> d,r;scanf("%s",s+1);for(int i=1;i<=n;i++){if(s[i]=='D')d.push(i);elser.push(i);}while(!d.empty()&&!r.empty()){int x=d.front(),y=r.front();//小的先做决策if(x<y){r.pop();//淘汰d.pop();//做完决策后等待下一轮 d.push(x+n);} else{d.pop();r.pop();r.push(y+n);}}if(d.empty())puts("R");elseputs("D");} return 0;}
0 0
- Codeforces 749C Voting 贪心+模拟
- Codeforces Round #388(Div. 2)C. Voting【贪心+模拟】
- CodeForces - 749C Voting 队列模拟
- codeforces 749C Voting
- codeforces 749C Voting
- 749 C. Voting codeforces
- Codeforces 749C-voting
- codeforces 749C Voting
- 【 codeforces 749C 】 Voting
- 【codeforces 749C】 Voting
- CodeForces - 749C Voting (队列)
- Codeforces Round #388 (Div. 2) C. Voting 贪心
- Codeforces Round #388 (Div. 2)C. Voting(数据结构+模拟)
- Codeforces Round #388 749C Voting
- C. Voting----模拟
- codeforces 388 C Voting
- 【Codeforces C Voting】
- Codeforces Round #388 (Div. 2) 749C Voting
- Android Studio报错:Unsupported method: AndroidProject.getPluginGeneration().
- selenium在IE、Chrome和Firefox运行
- CSS 颜色代码大全
- Makefile,详细栗子!!
- huffman 树
- Codeforces 749C Voting 贪心+模拟
- 【深入浅出jQuery】源码浅析2--奇技淫巧
- 解决IE8以下不支持getElementsByClassName的方法
- selenium-Java-运行chrome/ie/firefox
- Python安装过程遇到的问题及解决
- 正则验证函数 前后台 php验证,jquery前台验证
- selenium java服务器页面中涉及到框架定位
- mysql中的主从配置
- JBPM项目学习摘要