Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation
还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com)
题意
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- 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 ...
- 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 ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- DDD 领域驱动设计之面向对象思想
面向对象 面向对象是一种对世界理解和抽象的方法.那么对象是什么呢? 对象是对世界的理解和抽象,世界又代称为万物.理解世界是比较复杂的,但是世界又是由事物组成的. 正是这样的一种关系,认识事物是极其重要 ...
- Java8 中的流式数据处理
java8的流式处理极大了简化我们对于集合.数组等结构的操作,让我们可以以函数式的思想去操作,本篇文章将探讨java8的流式数据处理的基本使用. 一. 流式处理简介 在我接触到java8流式处理的时候 ...
- Java中获取applicationcontext(应用上下文)
package com.wl.iwbservice.util; import org.springframework.beans.BeansException; import org.springfr ...
- 千兆网数据CRC检验和过滤
项目简述 本次项目在计算机将图像数据信息通过千兆网发送给FPGA后,由于接收到的数据可能混乱和无效,需要对数据CRC校验和无效包过滤. 项目原理及框图 对iddr_ctrl模块的输入数据和使能信号,分 ...
- Oracle数据库 如何根据某个字段名的值去查询存在的表列表
declare v_sql varchar2(1000); data_count number; begin -- OWNER是模式名 tablespace_name是表空间 for cur_tabl ...
- 如何在网上找MySQL数据库的JDBC驱动jar包?
当我们在开发程序,涉及数据库时,总是需要用到相应的jar包,这不小编就给大家介绍一下如何下载相应的jar包 方法/步骤 1 在百度搜索栏上搜索MySQL 2 选择Downloads 3 选择 Co ...
- RabbitMQ 的集群?
镜像集群模式 你创建的 queue,无论元数据还是 queue 里的消息都会存在于多个实例上,然后每次你写消息到 queue 的时候,都会自动把消息到多个实例的 queue 里进行消息同步. 好处在于 ...
- 学习Haproxy (七)
haproxy是个高性能的tcp和http的反向代理.它就是个代理.不像nginx还做web服务器 官网地址为www.haproxy.org nginx的优点和缺点 ? 1 2 3 4 5 6 7 8 ...
- spring event
昨天看到了一遍关于spring event的帖子,觉得很好,就照着敲了一份代码,感觉对spring event有了进一步的认识.帖子链接:https://segmentfault.com/a/1190 ...
- 【推理引擎】如何在 ONNXRuntime 中添加新的算子
如果模型中有些算子不被ONNX算子库支持,我们就需要利用ONNXRuntime提供的API手动添加新算子.在官方文档中已经对如何添加定制算子进行了介绍(https://onnxruntime.ai/d ...