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

传送门  Problem - D - Codeforces

题意

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

题解

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

AC代码

  1. // #include<bits/stdc++.h>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <cstring>
  7. using namespace std;
  8.  
  9. typedef long long LL;
  10. typedef pair<char,int> PII;
  11. const int N = 2e5+10;
  12. PII a[N];
  13.  
  14. int main(void)
  15. {
  16. int t;
  17. cin >> t;
  18. while(t --)
  19. {
  20. int n;
  21. string s;
  22. cin >> n;
  23. for(int i = 0; i <n; i ++) cin >> a[i].second;
  24. for(int i = 0; i <n; i ++) cin >> a[i].first;
  25.  
  26. sort(a, a+n);
  27. bool flag = 1;
  28. for(int i = 0; i < n; i ++)
  29. {
  30. if(a[i].first == 'B'){
  31. if(a[i].second < i+1)
  32. {
  33. flag = 0;
  34. break;
  35. }
  36. }
  37. else{
  38. if(a[i].second > i+1)
  39. {
  40. flag = 0;
  41. break;
  42. }
  43. }
  44. }
  45. if(flag)puts("YES");
  46. else puts("NO");
  47. }
  48.  
  49. return 0;
  50. }

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 内部类

    内部类在 Java 里面算是非常常见的一个功能了,在日常开发中我们肯定多多少少都用过,这里总结一下关于 Java 中内部类的相关知识点和一些使用内部类时需要注意的点. 从种类上说,内部类可以分为四类: ...

  2. docker是干什么的,docker常用命令

    镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 一.百度百科 Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖到一个可移植的镜像中,然后发布到任何流行的Linux或Win ...

  3. Pyinstaller打包Pytorch框架所遇到的问题

    目录 前言 基本流程 一.安装Pyinstaller 和 测试Hello World 二.打包整个项目,在本机上调试生成exe 三.在新电脑上测试 参考资料 前言   第一次尝试用Pyinstalle ...

  4. 『现学现忘』Docker基础 — 32、通过DockerFile的方式挂载数据卷

    目录 1.简单了解一下DockerFile 2.通过DockerFile的方式挂载数据卷 (1)创建DockerFile文件 (2)编辑Dockerfile文件 (3)构建Dokcer镜像 (4)启动 ...

  5. python数据分析与挖掘实战————银行分控模型(几种算法模型的比较)

    一.神经网络算法: 1 import pandas as pd 2 from keras.models import Sequential 3 from keras.layers.core impor ...

  6. Serial 与 Parallel GC 之间的不同之处?

    Serial 与 Parallel 在 GC 执行的时候都会引起 stop-the-world.它们之间主要 不同 serial 收集器是默认的复制收集器,执行 GC 的时候只有一个线程,而 para ...

  7. 学习Kvm(三)

    虚拟化(将一个物理硬件平台虚拟成多个) vmware(模拟出一堆硬件设备,每一个硬件设备都是独立平台) 虚拟化要解决的问题(硬件之上的OS,有用户空间.内核空间:vmware虚拟机所模拟出的多个硬件平 ...

  8. 通过pink构造简易部署脚本

    安装git        https://www.cnblogs.com/youxiu326/p/10540753.html 安装maven https://www.cnblogs.com/youxi ...

  9. (stm32学习总结)—对寄存器的理解 _

    芯片里面有什么 我们看到的 STM32 芯片是已经封装好的成品,主要由内核和片上外设组成.若与电脑类比,内核与外设就如同电脑上的 CPU 与主板.内存.显卡.硬盘的关系.STM32F103 采用的是 ...

  10. 【转载】10个Web3D可视化精彩案例

    1.化学元素周期表 六种排列方式,炫酷动画效果,TWaver 3D轻松实现. 演示地址:http://demo.servasoft.com/che... 2.DNA螺旋图 DNA3D模型,包含几千个球 ...