B - Colorful Stamp

#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<set>
#include<climits>
#include<queue>
#include<cstring>//memset头文件
using i64 = int64_t;
using namespace std;
#define endl '\n'
#define int i64
const int maxn = 100;
int num[maxn];//记录字符串个数
void slove()
{
    //不存在wbw俩个w中间夹着一个其他颜色
    //不存在BB 相同染色的边缘为没有另外一种颜色
    // == >> 以W作为切割的话,每一个子串都至少有俩种颜色
    int n;
    string str;
    cin >> n >> str;
    bool is = true;
    if(n == 1 && str != "W")is = false;
    else if(n == 2)
    {//长为2进行染色不存在白
        int num_w = count(str.begin(),str.end(),'W');
        int num_B = count(str.begin(),str.end(),'B');
        int num_R = count(str.begin(),str.end(),'R');
        if(num_w == 1)is = false;
        if(num_B == 2 || num_R == 2)is = false;
    }
    else 
    {
        vector<string>v;
        string t = "";
        for(int i = 0;i < n && is;i++)
        {
            if(str[i] == 'W' && t != "")
            {
                if(t.find('B') == t.npos && t.find('R') != t.npos)is = false;
                if(t.find('B') != t.npos && t.find('R') == t.npos)is = false;
                t = "";
            }
            else
                t += str[i];
        }
        if(t != "")
        {
             if(t.find('B') == t.npos && t.find('R') != t.npos)is = false;
            if(t.find('B') != t.npos && t.find('R') == t.npos)is = false;
        }
    }
    is ? cout << "YES" << endl : cout << "NO" << endl;
}

signed main()
{
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while(T--)
        slove();
    return 0;
}

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值