1.题目描述:
2.题意概述:
类似于UNO的游戏,当某人在回合当中可以禁言某人,使得某人这个回合不能发动技能,然后问你最后赢得是谁
3.解题思路:
把每个队伍的人丢到队列里面,每次取顶部相当于发言嘛,然后贪心地“影响”敌人——轮到第i人(D)投票时,应选择把下一个能做决策的对手X(R)淘汰(既淘汰掉一个人,又防止下一个D被淘汰,即可能又多了一次淘汰(R)的机会)
4.AC代码:
#include <string.h>
#include <stdio.h>
#include <queue>
#define maxn 200200
using namespace std;
char a[maxn];
int vis[maxn];
int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
memset(vis, 0, sizeof(vis));
scanf("%s", a);
queue<int>d;
queue<int>r;
for (int i = 0; i < n; i++)
if (a[i] == 'D')
d.push(i);
else
r.push(i);
while (!d.empty() && !r.empty())
{
for (int i = 0; i < n; i++)
{
if (vis[i])
continue;
if (a[i] == 'D')
{
int tmpd = d.front();
d.pop();
int tmpr = r.front();
r.pop();
vis[tmpr] = 1;
d.push(tmpd);
}
else
{
int tmpr = r.front();
r.pop();
int tmpd = d.front();
d.pop();
vis[tmpd] = 1;
r.push(tmpr);
}
if (d.empty() || r.empty())
break;
}
}
if (!d.empty())
puts("D");
else
puts("R");
}
return 0;
}