题目是Codeforces Round #388 (Div. 2) 的C题
分析:策略是采取先deny第一个后于自己位置的对手,如果自己后面没对手了就投剩下的对手中位置最靠前的,道理显而易见,位置越前越有可能deny自己阵容的人,肯定要先“让他说不了话”比较合理
一开始直接数组模拟,while(1)遍历数组居然还能过前20多组数据,但这样效率奇低,后来想用优先队列(最小堆),每次把对面的根节点deny,但这样不能保证是最优,例如样test21的数据
7
RDRDDRD
这样写WA,原因是第三个D选择deny的是第一个R而不是紧跟他的下一个R ,这显然坑队友,第四个D会被第三个R搞死(deny),
//WA 21 的版本
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = 200005;
char s[maxn];
priority_queue<int,vector<int>,greater<int> > d,r;
int a[maxn]={
0},b[maxn]={
0};
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s);
int i=0;
for(i=0;i<n;++i){
if(s[i]=='D'){
d.push(i);
a[i]=