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 ...
随机推荐
- Asp.net Core Filter过滤器异常处理
本文旨在: 1 继承ExceptionFilterAttribute,重写Override OnException(ExceptionContext context)处理异常 2 在.netCore中 ...
- Java的自动装箱与拆箱(Autoboxing and unboxing)
一.什么是自动装箱拆箱 很简单,下面两句代码就可以看到装箱和拆箱过程 1 //自动装箱 2 Integer total = 99; 3 4 //自动拆箱 5 int totalprim = total ...
- SpringMVC实现文件上传功能
文件上传 文件上传要求form表单的请求方式必须为post,并且添加属性enctype="multipart/form-data" SpringMVC中将上传的文件封装到Multi ...
- kafka端口和zookeeper端口
一.问题描述 今天配合现场联调一个数据工具,工具使用到了kafka,程序启动之后包如下错误: [WARN ] [2020-08-17 19:17:27] [org.apache.kafka.clien ...
- Springmvc入门基础(三) ---与mybatis框架整合
1.创建数据库springmvc及表items,且插入一些数据 DROP TABLE IF EXISTS `items`; CREATE TABLE `items` ( `id` int(11) NO ...
- FiddlerEverywhere注册账号进行激活失效问题
有关FiddlerEverywhere通过邮件激活账号时,激活链接提示已失效问题:这个链接有进行一个讨论(https://www.telerik.com/forums/unable-to-activa ...
- Java连接ArtemisMQ,出现Timed out waiting to receive cluster topology. Group:null异常
完整异常内容:org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JM ...
- 为什么 wait 和 notify 方法要在同步块中调用?
Java API 强制要求这样做,如果你不这么做,你的代码会抛出 IllegalMonitorStateException 异常.还有一个原因是为了避免 wait 和 notify 之间产生竞态条件.
- 转:master公式(主方法)
master公式(也称主方法)是利用分治策略来解决问题经常使用的时间复杂度的分析方法,(补充:分治策略的递归解法还有两个常用的方法叫做代入法和递归树法),众所众知,分治策略中使用递归来求解问题分为三步 ...
- 运筹学之"最大最大决策标准"和"最大最小决策标准"
一.最大最大决策标准的解题思路就是:先比较出所有行的最大值,在最大值中选出最大值,最后这个最大是那行的就选哪个方案 二.最大最小决策标准的解题思路就是:先比较出所有行的最小值,在最小值中选出最大值,最 ...