• 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
    ");
            for (int i=0;i<ans.size();++i)
            {
                printf ("%d ",ans[i]);
            }
            printf ("
    ");
        }
        else printf ("N
    ");
        return ;
    }
    
    
    int main()
    {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        int t;
        scanf ("%d",&t);
        while(t--) work();
        return 0;
    }
    View Code
  • 相关阅读:
    各系统添加根证书
    Nginx浏览目录配置及美化
    django-图形验证码(django-simple-captcha)
    django-manage.py参数
    js — 对象
    js — 数组Array
    js — 字符串
    js — 基础知识
    css — 定位、背景图、水平垂直居中
    css — 权重、继承性、排版、float
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/5763021.html
Copyright © 2020-2023  润新知