Given a sequence, can only take D, next door will flip, ask can all take away.
Notice that if you can take it, it's okay to take the order of D. Simulation can
#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>Const intMAXN = 1e5+ -;CharSTR[MAXN];CharSUB[MAXN];voidWork () {Charbook[ the]; book['B']='D'; book['D']='B'; intN; scanf ("%d",&N); scanf ("%s", str+1); strcpy (Sub+1, str+1); intDid=0; intCnt=0; Vector<int>ans; intbegin=1; intflag=0; for(intI=1; i<=n;++i) {if(str[i]=='D') {flag=1; CNT++; did+=CNT; CNT=0; Str[i+1]=book[str[i+1]]; for(intj=i;j>=begin;--j) {Ans.push_back (j); } Begin=i+1; } Elsecnt++; } if(did==N) {printf ("y\n"); for(intI=0; I<ans.size (); + +i) {printf ("%d", Ans[i]); } printf ("\ n"); } Elseprintf ("n\n"); return ;}intMain () {#ifdef local freopen ("Data.txt","R", stdin);#endif intT; scanf ("%d",&t); while(t--) work (); return 0;}
View Code
Gym 101047M removing coins in Kem kadrãn