ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
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
4
3
BDB
5
DBDDB
5
DDBDD
6
DBBBBB
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 - 暴力的更多相关文章
- Gym 101047M Removing coins in Kem Kadrãn
给定一个序列,只能拿走D,隔壁的会翻转,问能否全部拿走. 注意到如果能拿走的话,拿D的顺序是没关系的.模拟即可 #include <cstdio> #include <cstdlib ...
- ACM: Gym 100935F A Poet Computer - 字典树
Gym 100935F A Poet Computer Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d &am ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- Gym 101606F - Flipping Coins - [概率DP]
题目链接:https://codeforc.es/gym/101606/problem/F 题解: 假设 $f[i][j]$ 表示抛 $i$ 次硬币,有 $j$ 个硬币正面朝上的概率. 所以只有两种挑 ...
- 杭电ACM hdu 1398 Square Coins
Problem Description People in Silverland use square coins. Not only they have square shapes but also ...
随机推荐
- Open xml 操作Excel 透视表(Pivot table)-- 实现Excel多语言报表
我的一个ERP项目中,客户希望使用Excel Pivot table 做分析报表. ERP 从数据库中读出数据,导出到Excel中的数据源表(统一命名为Data),刷新Pivot table! 客户还 ...
- PYTHON map()函数详解
map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回. 栗子如下↓ 图片来自于网上 def f(x,a): return x+x ...
- C#夯实基础之多线程三:线程的优先级
一.为什么需要优先级--线程调度的问题 在现实生活中,优先级是一个很常见的现象:在火车站,如果你是孕妇,你是可以走进站中的专门绿色通道的,可以提前上火车以免拥挤:火警119匪警110出警的时候,都是人 ...
- 小波包分解 仿真 matlab
clc;close all;clear;fs = 100000;t = 1: 100;x = sin(2*pi*4000* t/fs) + sin(2*pi*40000*t/fs); %db8[Lo_ ...
- Mysql 存储引擎中InnoDB与Myisam的主要区别
一直以为我spring事物没有配置好,结果发现是mysql的表本身设置成了Myisam 引擎.改成innodb就支持事物了. 1, 事务处理 innodb 支持事务功能,myisam 不支持. Myi ...
- 如何做JS 单体模式的设计---->>js设计模式<<-------单体模式
1. 单体模式是js中最基本 单最有用的模式之一,非常常用. 单体模式的基本结构如下: var Person = { name: 'lilu', age:', sayHi: function(){ a ...
- SQL 统计两个表的数据,按同一日期分组
思路:把两个表的数据按日期整合到临时表在按日期分组,求和. 例子: SELECT t.dateTime AS '日期',SUM(t.money) AS '表1利息',SUM(t.interest) A ...
- linux下误删mysql的root用户,解决方法
开始对liunx界面不熟悉,可能由于不小心,把root误删了,怎么办? 1. # killall mysqld 干掉所有mysql进程 2. # mysqld_safe --skip-grant ...
- 整数转IP地址
将一个整数,比如1567898765转换为xxx.xxx.xxx.xxx的IP地址的形式, 以下是源代码 union IPNode{ unsigned int addr; struct { unsig ...
- 鱼搜_鱼搜官网_鱼搜搜索_http://www.7yusou.com
收集了N多视频小站,然后花了3天时间弄了一个鱼搜搜索网站.欢迎大家访问哟. http://www.7yusou.com
