CodeForces Gym 101047M Removing coins in Kem Kadrãn 暴力

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的牌子 翻了后这张牌消失 相邻的牌转面 问可不可以把所有的牌拿掉 可以的话打印路径
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int,int> PII;
const double PI = acos(-1);

const int MAXN = 1e5 + 5;

char card[MAXN];
int vis[MAXN];
int path[MAXN];
int T, n;
int cas;

int main()
{
    //FIN
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        scanf("%s", card);
        cas = 0;
        int num = n;
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < n; i ++)  if(card[i] == 'D')  {vis[i] = 1;}
        for(int i = 0; i < n; i ++){
            if(vis[i]){
                for(int j = i; j >= 0; j --){
                    if(vis[j] == 0)  break;
                    if(vis[j] == -1)  break;
                    //cout<<j<<" ";
                    num --;
                    vis[j] = -1;
                    path[cas++] = j;
                    if(j == 0 && i == 0)  {vis[1] = !vis[1]; continue;}
                    if(j == n - 1 && vis[j - 1] != -1)  {vis[j - 1] = !vis[j - 1]; continue;}
                    if(j > 0 && vis[j - 1] != -1)  vis[j - 1] = !vis[j - 1];
                    if(j < n - 1 && vis[j + 1] != -1)  vis[j + 1] = !vis[j + 1];
                }
            }
        }
        //cout<<endl;
        //cout<<num<<endl;

        if(num == 0){
            puts("Y");
            printf("%d", path[0] + 1);
            for(int i = 1; i < cas; i ++){
                printf(" %d", path[i] + 1);
            }
            printf("\n");
        }
        else  puts("N");


    }

}

  



转载于:https://www.cnblogs.com/Hyouka/p/5801985.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值