Gym 101047M removing coins in Kem kadrãn

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.