CF749C Voting
题目链接:
http://codeforces.com/problemset/problem/749/C
题目大意:
共有n个人,编号为1~n。他们每个人属于且仅属于R阵营或N阵营中的一个。现在他们要进行一场投票。投票可能进行多轮,每一轮投票都是按照从1~n的顺序,当轮到某一人投票的时候,他可以什么都不做,也可以随便挑选一人使他丧失投票的权利。每个人都会代表自己阵营的利益。一个人如果丧失了投票权利,则他直到这场投票结束都不能再投票。投票直到某一阵营一个人都没有的时候就会结束,此时一个人都没有的阵营失败,另一个阵营获胜。
现在给定每个人所属的阵营,问最后哪个阵营会获胜。
解题思路:
采用贪心的思路,每个人都干掉自己后面投票的第一个对手。
具体来说就是用两个队列来模拟两个阵营。分别为D-队列和R-队列。初始分别按顺序加入自己阵营的所有人的编号。每次队头的两个人pk,编号小的一方获胜,将获胜方编号+n并且push到队尾(表示本轮投票结束,将进行下轮投票),失败方直接从本方队列中pop掉即可。最终队列空的一方失败,另一方获胜。
代码:
#include <iostream>
#include <string>
#include <cstdio>
#include <queue>
using namespace std; int n;
string s; int main()
{
cin >> n >> s;
queue<int> qd, qr;
for (int i = ; i < n; i++)
{
if (s[i] == 'D')
{
qd.push(i);
}
else
{
qr.push(i);
}
}
while (!qd.empty() && !qr.empty())
{
if (qd.front() < qr.front())
{
qr.pop();
qd.push(qd.front() + n);
qd.pop();
}
else
{
qd.pop();
qr.push(qr.front() + n);
qr.pop();
}
}
if (qd.empty())
{
cout << "R" << endl;
}
else
{
cout << "D" << endl;
}
return ;
}
CF749C Voting的更多相关文章
- 11G RAC 中 OCR 及Voting Disk 相关操作
一.启动oracle clusterware先决条件:Oracle High Availability Services daemon(OHASD)运行在所有集群节点上1.启动整个Oracle Clu ...
- UVA10142/PC110108Australian Voting
UVA10142/PC110108Australian Voting 10142 Australian Voting Accepted C++11 0.769 2014-02-11 05:01:20 ...
- windows 环境怎样恢复 (oracle 11g grid) ocr voting 损坏的集群
windows 环境怎样恢复 (oracle 11g grid) ocr voting 损坏的集群 oracle 11g 以后 ocr 能够放到 asm 磁盘上,而ASM的启动依赖于ocr和vo ...
- 11g r2 模拟OCR和voting disk不可用,完整恢复过程,以及一些注意事项
环境:RHEL5.8 RAC 11.2.0.3.0 1:查看ORC和voting disk信息: In 11g Release 2 your voting disk data is automatic ...
- Voting
Voting time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Graphical Analysis of German Parliament Voting Pattern
We use network visualizations to look into the voting patterns in the current German parliament. I d ...
- CSA Round #54 $\ $Voting
CSA Round #54 \(\ \)Voting 题目大意: 原题网址:戳我戳我! 一次歌唱比赛中,一位歌手刚刚结束表演,评委正在打分. 一共有 \(n\) 位评委,他们每人可以打 \(1\) 分 ...
- Solidity by Example详解 - Voting
Example地址:https://solidity.readthedocs.io/en/develop/solidity-by-example.html#voting Voting程序的功能: 这个 ...
- Oracle 10g RAC OCR、Voting disk更换
环境:OEL 5.7 + Oracle 10.2.0.5 RAC 需求:更换存储,OCR.Voting disk同时需要更换到新存储. 1.替换OCR 2.替换voting disk 1.替换OCR ...
随机推荐
- POJ1087 A Plug for UNIX —— 最大流
题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K T ...
- POJ3414 Pots —— BFS + 模拟
题目链接:http://poj.org/problem?id=3414 Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...
- SET IDENTITY_INSERT 和 DBCC CHECKIDENT
SET IDENTITY_INSERT (Transact-SQL) Allows explicit values to be inserted into the identity column of ...
- poj 2253 Frogger 解题报告
题目链接:http://poj.org/problem?id=2253 题目意思:找出从Freddy's stone 到 Fiona's stone 最短路中的最长路. 很拗口是吧,举个例子.对 ...
- hdu-5676 ztr loves lucky numbers(乱搞题)
题目链接: ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- codeforces 673A A. Bear and Game(水题)
题目链接: A. Bear and Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- fasttext(1) -- 认识 fasttext 和 初步使用
fastText 的 Python接口:https://github.com/salestock/fastText.py (1) fasttext 简介:FastText是Facebook开发的一款快 ...
- 洛谷 P3957 跳房子 —— 二分答案+单调队列优化DP
题目:https://www.luogu.org/problemnew/show/P3957 先二分一个 g,然后判断: 由于转移的范围是一个区间,也就是滑动窗口,所以单调队列优化: 可以先令队尾为 ...
- Allure生成测试报告
Allure 使用 安装 adapter 如果要在 pytest 中使用 Allure,需要使用一个 Adaptor Allure Pytest Adaptor 安装 pytest-allure-ad ...
- BackTrack5(BT5)各版本下载
BT5R3(最新版本)http://www.nigesb.com/backtrack-5-r3-released.html BT5R2KDE版32位: http://ftp.halifax.rwth ...