Gym 101047M Removing coins in Kem Kadrãn

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

standard input/output

Andréh and his friend Andréas are board-game aficionados. They know many of their friends would love to go on a trip to Phuket, Thailand, and so they want to challenge them at Kem Kradãn, a traditional Thai board game.

Kem Kradãn (เกมกระดาน) has been played since the 2nd century AD. The game is played with N pieces where each piece has two faces, one of which is golden and the other is white. The game starts with all pieces arranged in a line on the board and they are numbered from 1 to N from left to right. When a piece numbered i has its golden face up, it can be removed from the board. When this is done, the pieces numbered i - 1 and i + 1 are flipped, if they're still there. The goal is to remove all game pieces.

Before challenging their friends, Andréh and Andréas want to make sure their initial configurations have a solution. To help them, given an initial configuration, you must determine if it is possible to remove all game pieces and, if so, you must show how to do it.

Input

The first line has a single integer T, the number of test cases.

Each test case is formed by a line containing an integer N, the number of pieces, followed by line containing a string of length Ncontaining only the letters B (white face up) and D (golden face up), representing the initial state of the game.

Limits

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 105
  • The sum of N over all test cases will not exceed 5·105

Output

For each test case, print a line containing Y if it is possible to remove every piece from the board, or N otherwise. In case it is possible to remove all the pieces, you should also print on the next line a sequence of N integers each representing a piece number, indicating the order in which the pieces must be removed. If there is more than one possible sequence, you can print any of them.

Sample Input

Input
4
3
BDB
5
DBDDB
5
DDBDD
6
DBBBBB
Output
Y
2 3 1
Y
4 5 1 2 3
N
Y
1 2 3 4 5 6
/*/
题意:
在一段字符里面有两种字符D和B,字符串中D可以直接拿掉,但是D两边的都要进行反转,B->D , D->B ,问能不能把所有的字符全部拿掉。 如果可以输出Y并且打印拿的过程。 如果不能就输出N。

暴力扫描,如果找到一个D那么从D开始往前面去拿掉字符串,如果前面的不能被拿掉,那么肯定这个字符串是不能被拿掉的。
举个栗子:
AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdio"
using namespace std; int main() {
int T,n;
int ans[111111],light[111111];
char s[111111];
cin>>T;
while(T--) {
memset(s,0,sizeof(s));
memset(ans,0,sizeof(ans));
memset(light,0,sizeof(light));
cin>>n;
scanf("%s",s+1);
for(int i=1; i<=n; i++) {
if(s[i]=='B')light[i]=2;
else light[i]=1;
}
int j;
int erear=0;
for(int i=1; i<=n; i++) {
j=i;
while(light[j]==1) {
if(j<=0)break;
if(j> n)break;
light[j]=0;
ans[erear++]=j;
if(light[j-1]==2)light[j-1]=1;
else if(light[j-1]==1)light[j-1]=2;
if(light[j+1]==2)light[j+1]=1;
else if(light[j+1]==1)light[j+1]=2;
j--;
}
}
int t=1;
if(erear==n) {
puts("Y");
for(int i=0; i<erear; i++) {
if(t)t=0;
else printf(" ");
printf("%d",ans[i]);
}
puts("");
} else puts("N");
}
return 0;
}

  

 

ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力的更多相关文章

  1. Gym 101047M Removing coins in Kem Kadrãn

    给定一个序列,只能拿走D,隔壁的会翻转,问能否全部拿走. 注意到如果能拿走的话,拿D的顺序是没关系的.模拟即可 #include <cstdio> #include <cstdlib ...

  2. ACM: Gym 100935F A Poet Computer - 字典树

    Gym 100935F A Poet Computer Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d &am ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. ACM: Gym 100935B Weird Cryptography - 简单的字符串处理

    Weird Cryptography Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  7. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  8. Gym 101606F - Flipping Coins - [概率DP]

    题目链接:https://codeforc.es/gym/101606/problem/F 题解: 假设 $f[i][j]$ 表示抛 $i$ 次硬币,有 $j$ 个硬币正面朝上的概率. 所以只有两种挑 ...

  9. 杭电ACM hdu 1398 Square Coins

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

随机推荐

  1. NFS配置(centos)

    一.简介    NFS(Network File System/网络文件系统):       1).设置Linux系统之间的文件共享(Linux与Windows中间文件共享采用SAMBA服务): 2) ...

  2. jquery 页面滚动到底部自动加载插件集合

    很多社交网站都使用无限滚动的翻页技术来提高用户体验,当你页面滑到列表底部时候无需点击就自动加载更多的内容.下面为你推荐 10 个 jQuery 的无限滚动的插件: 1. jQuery ScrollPa ...

  3. [原创]webapp/css3实战,制作一个《炉石传说》宣传页

    在移动网页,尤其是webapp中常需要用到大量的css3动画,来获得良好交互体验 我之前帮朋友做了一个,可惜没帮上忙现在和大家分享一下 目标是要做一个<炉石传说>游戏的介绍宣传页面,文字内 ...

  4. Markdown编辑器:Typora

    现在网上的Markdown有很多,各有各的特色,同时也有各自的缺点.比如有的传图片比较麻烦,有的导出pdf需要付费,有的数学公式编辑比较麻烦等等...... 而最近接触到Typora,发现这真是一款良 ...

  5. Qt - 读取GPS数据

    1.GPS型号为ublox(EVK-M8L),配有USB接口,Qt版本5.7 2.实现步骤: (1)实现串口通信 采用Qt5.7 内置的串口操作类QSerialPort和QSerialPortInfo ...

  6. Linux sort 命令

    - 今天的收获: sort -t $'\t' 说明:sort 加-t 参数时,如果需要以 '\t' 分隔,需要写成上述形式.

  7. jQuery cookie使用

    什么是jquery cookie? A simple, lightweight jQuery plugin for reading, writing and deleting cookies. Usa ...

  8. 【安装Redis】CentOS7 下安装NodeJs+Express+MongoDB+Redis

    Redis,V3.2,官网l官方链接:http://www.redis.io/download,参考:http://blog.csdn.net/mlks_2008/article/details/19 ...

  9. js创建命名空间

    CreateNameSpace: function () { var nameSpaceObjec = arguments[0].split('.'); var currentNameSpaceNam ...

  10. CC2540串口输出调试功能

    可以用printf()做串口打印输出 这个功能非常简单,首先在工程管理下的preprocessor把串口打开HAL_UART=TRUE. 然后看我的npi.c文件,多了什么自己琢磨,懒点的就直接复制吧 ...