• 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
  • 相关阅读:
    MFC中注释含义
    数字时钟
    布线问题分支限界法
    精度计算大数阶乘ACM常用算法
    C++库大全
    简单文本编辑器制作windows程序设计雏形
    使用计时器方法2
    MFC常用基本数据类型
    Xcode 代码格式化/自动排版
    android的color值
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/5763021.html
Copyright © 2020-2023  润新知