还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com)

传送门  Problem - D - Codeforces

题意

n个数字,n个字符, 数字与字符一一对应, 其中字符R红色代表数字可以上升, B蓝色代表可以下降, 问一顿操作下来能否使n个数含有1~n的所有数

题解

当时真的没想到, 蓝色一定在数组前面, 红色一定在数组后面,( 反正就算有方案使得蓝不在前面, 红不在后面,蓝红也是可以交换的)。 排序后, 前面的蓝色数字如果>=i+1 或者红色的数字<=i+1 即可, 不符合条件的数最后都没有去处

AC代码

// #include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std; typedef long long LL;
typedef pair<char,int> PII;
const int N = 2e5+10;
PII a[N]; int main(void)
{
int t;
cin >> t;
while(t --)
{
int n;
string s;
cin >> n;
for(int i = 0; i <n; i ++) cin >> a[i].second;
for(int i = 0; i <n; i ++) cin >> a[i].first; sort(a, a+n);
bool flag = 1;
for(int i = 0; i < n; i ++)
{
if(a[i].first == 'B'){
if(a[i].second < i+1)
{
flag = 0;
break;
}
}
else{
if(a[i].second > i+1)
{
flag = 0;
break;
}
}
}
if(flag)puts("YES");
else puts("NO");
} return 0;
}

Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation的更多相关文章

  1. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  2. Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学

    — This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...

  3. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  4. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  5. Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

    Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...

  6. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  7. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  8. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  9. Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

随机推荐

  1. 最新出炉的Java面试题(2022亲身经历)

    面试题清单 个人近来面试了不少的公司的,该挂的挂,该应付通过的应付通过,目前对面试题部分做一个系统的总结.最起码要保证被问过的问题第二次被问到的时候是可以回答并且理解的.算是一个被动输入学习的过程. ...

  2. springboot常用的starter有哪些?

    spring-boot-starter-web 嵌入tomcat和web开发需要servlet与jsp支持 spring-boot-starter-data-jpa 数据库支持 spring-boot ...

  3. mac 安装shell

    https://blog.csdn.net/weixin_41937552/article/details/108565705

  4. POI Excel索引是从0还是1开始??

    this.workbook.getSheetAt(1).getFirstRowNum() // == 0 this.workbook.getSheetAt(1).getLastRowNum() // ...

  5. Java并发机制(3)--volatile关键字与内存模型

    Java并发编程:volatile关键字解析及内存模型 个人整理自:博客园-海子-http://www.cnblogs.com/dolphin0520/p/3920373.html 1.线程内存模型: ...

  6. 【代码开源】GreaterWMS 抖音SDK调用教程

    应用介绍 GreaterWMS 抖音SDK调用教程 SDK具体功能: 1,一仓多店,多仓多店 2,库存同步,商品同步 3,快递发货,物流轨迹 4,订单拦截 5,字节云仓 6,精选联盟 7,供应分销 8 ...

  7. web app遇到的一些坑及小技能(持续更新...)

    遇到的一些坑 问题:手机端 click 事件会有大约 300ms 的延迟 原因:手机端事件 touchstart --\> touchmove --> touchend or touchc ...

  8. 居中的css:完全指南(翻译)

    这里主要参考的是CHRIS COYIER写的一篇的文章(点击查看),主要讲了关于css水平.垂直居中的一些方法,每个方法后面都有一个demo,可以在线查看效果. 1 水平 水平居中有行内元素和块元素, ...

  9. 「腾讯视频」微信小程序插件介绍

    上期,我们在<从原理到应用,一文带你了解小程序插件能力>一文中介绍了小程序插件的意义.作用以及应用.今天开始,我们会每期与大家分享一款优秀的小程序插件,从使用场景到使用方法,都将作出详细的 ...

  10. 前端存储 - localStorage

    发布自Kindem的博客,欢迎大家转载,但是要注意注明出处 localStorage 介绍 在HTML5中,引入了两个新的前端存储特性: localStorage sessionStorage 这两者 ...