Gym 101047M Removing coins in Kem Kadrãn

给定一个序列,只能拿走D,隔壁的会翻转,问能否全部拿走。

注意到如果能拿走的话,拿D的顺序是没关系的。模拟即可

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e5+20;
char str[maxn];
char sub[maxn];

void work ()
{
    char book[256];
    book[‘B‘]=‘D‘;
    book[‘D‘]=‘B‘;
    int n;
    scanf("%d",&n);
    scanf("%s",str+1);
    strcpy(sub+1,str+1);

    int did=0;
    int cnt=0;
    vector<int>ans;
    int begin=1;
    int flag=0;
    for (int i=1;i<=n;++i)
    {
        if (str[i]==‘D‘)
        {
            flag=1;
            cnt++;
            did += cnt;
            cnt=0;
            str[i+1]=book[str[i+1]];
            for (int j=i;j>=begin;--j)
            {
                ans.push_back(j);
            }
            begin=i+1;
        }
        else cnt++;
    }

    if (did==n)
    {
        printf ("Y\n");
        for (int i=0;i<ans.size();++i)
        {
            printf ("%d ",ans[i]);
        }
        printf ("\n");
    }
    else printf ("N\n");
    return ;
}

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    int t;
    scanf ("%d",&t);
    while(t--) work();
    return 0;
}

时间: 2024-12-23 04:28:26

Gym 101047M Removing coins in Kem Kadrãn的相关文章

ACM: Gym 101047M Removing coins in Kem Kadr&#227;n - 暴力

Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Practice Description standard input/output Andréh and his friend Andréas are board-game aficionados. They know many of their friends

CodeForces Gym 101047M Removing coins in Kem Kadr&#227;n 暴力

Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Gym 101047M Description standard input/output Andréh and his friend Andréas are board-game aficionados. They know many of their friends would lo

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

题目链接:https://codeforc.es/gym/101606/problem/F 题解: 假设 $f[i][j]$ 表示抛 $i$ 次硬币,有 $j$ 个硬币正面朝上的概率. 所以只有两种挑选硬币的情况: 1.正面硬币数量为 $[0,n-1]$,选择反面硬币抛,则正面硬币数量比原本增加 $1$ 或者不变. 2.正面硬币数量为 $n$,随便选择一个硬币抛,则正面硬币数量比原本减少 $1$ 或者不变. 因此可得状态转移方程: 对于 $j<n$,有 f[i+1][j+1]+=f[i][j]*

AGC033C Removing Coins(博弈论+思维)

这也太强了8--AtCoder真的道道好题 考虑一条链上的情况--这不SB题吗,按\(\% 3\)的余数考虑:\(\% 3\)余2后手赢,否则先手赢 扩展到树上,每次删除都会使直径删除1个或2个点.直径删完时其它链肯定也删完了,所以对直径按照上边的方法预处理下SG函数就行了 代码 #include <bits/stdc++.h> #define N 200005 #define pb push_back using namespace std; bool SG[N]; vector<in

AtCoder AGC033C Removing Coins (博弈论)

题目链接 https://atcoder.jp/contests/agc033/tasks/agc033_c 题解 终于会做点最简单的博弈论了-- 首先题目中操作的含义就是选定一个点,把所有不是这个点的叶子删掉(如果这个点不是叶子就删所有叶子). 对于任何一棵点数不少于\(3\)的树,一定存在一个点(比如非叶子节点),使得对该点操作之后直径减少\(2\):同时一定存在一个点(比如直径的端点),使得对该点操作后直径减少\(1\):同时不存在任何一种操作使得直径发生其他的变化.因此这是一个Bash博

AtCoder刷题记录

神仙AtCoder思维量巨大,很适合我用来提高智商qwq ARC066C Addition and Subtraction Hard 首先要发现两个性质. 加号右边不会有括号 显然,有括号也可以被删去. \(op_i\)和\(A_{i+1}\)之间只会有一个括号 有多个括号的话只保留最外边那个,显然答案不变. 然后就可以定义状态:\(dp_{i,j}\)表示前\(i\)个数,还有\(j\)个未闭合的左括号,得到的最大答案. 由于只有减号右边有括号,所以只要知道左边有几个未闭合的左括号,就可以知道

Asp.net Core认证和授权:Cookie认证

这里我只是记录下自己在学习中的点滴和一些不懂的地方 Cookie一般是用户网站授权,当用户访问需要授权(authorization)的页面,程序会判断是否已经授权,并认证 添加认证代码:引入命名空间:Microsoft.AspNetCore.Authentication.Cookies; 添加服务 publicvoidConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion

【动态规划】Gym - 101102A - Coins

Hasan and Bahosain want to buy a new video game, they want to share the expenses. Hasan has a set of N coins and Bahosain has a set of M coins. The video game costs W JDs. Find the number of ways in which they can pay exactly W JDs such that the diff

抛硬币 Flipping Coins(Gym - 101606F)

Here's a jolly and simple game: line up a row of N identical coins, all with the heads facing down onto the table and the tails upwards, and for exactly K times take one of the coins, toss it into the air, and replace it as it lands either heads-up o