Codeforces Round #648 (Div. 2) B. Trouble Sort
一开始读错题了...想当然地认为只能相邻元素交换...(然后换了两种写法WA了4发,5分钟切A的优势荡然无存)
题目链接:https://codeforces.com/contest/1365/problem/B
题意
有 $n$ 个数,每个数的种类为 $0$ 或 $1$,不同种类的元素可以任意交换,问这些数能否排为非递减序。
题解
如果两个种类都有,一定可以排为有序,稍微证明一下:
- 将种类为 $0$ 的数都交换到最左边,种类为 $1$ 的数都交换到最右边
- 每个种类的数可以利用另一个种类的一个数作为中转进行内部排序
- 最后再对两个种类进行整体排序即可
如果只有一种判断是否已排序即可。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n]; for (auto &i : a) cin >> i;
int b[n]; for (auto &i : b) cin >> i;
sort(b, b + n);
bool ok = true;
if (b[0] == b[n - 1])//只有一种
ok = is_sorted(a, a + n);
cout << (ok ? "Yes" : "No") << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
Codeforces Round #648 (Div. 2) B. Trouble Sort的更多相关文章
- Codeforces Round #486 (Div. 3)-B. Substrings Sort
B. Substrings Sort time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #198 (Div. 2) D. Bubble Sort Graph (转化为最长非降子序列)
D. Bubble Sort Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #212 (Div. 2) C. Insertion Sort
C. Insertion Sort Petya is a beginner programmer. He has already mastered the basics of the C++ lang ...
- Codeforces Round #648 (Div. 2)
链接 : https://codeforces.com/contest/1365/problems problem A 统计可用的行和列的最小值, 模2输出即可 /* * Author: RoccoS ...
- Codeforces Round #648 (Div. 2) E. Maximum Subsequence Value(鸽巢原理)
题目链接:https://codeforces.com/problemset/problem/1365/E 题意 有 $n$ 个元素,定义大小为 $k$ 的集合值为 $\sum2^i$,其中,若集合内 ...
- Codeforces Round #648 (Div. 2) D. Solve The Maze
这题犯了一个很严重的错误,bfs 应该在入队操作的同时标记访问,而不是每次只标记取出的队首元素. 题目链接:https://codeforces.com/contest/1365/problem/D ...
- Codeforces Round #648 (Div. 2) C. Rotation Matching
题目链接:https://codeforces.com/contest/1365/problem/C 题意 有两个大小为 $n$ 的排列,可以循环左移或右移任意次,问最多有多少对同一值在同一位置. 题 ...
- Codeforces Round #648 (Div. 2) A. Matrix Game
题目链接:https://codeforces.com/contest/1365/problem/A 题意 给出一个 $n \times m$ 的网格,两人轮流选择一个所在行列没有 $1$ 的方块置为 ...
- Codeforces Round #648 (Div. 2) F. Swaps Again
题目链接:F.Swaps Again 题意: 有两个长度为n的数组a和数组b,可以选择k(1<=k<=n/2)交换某一个数组的前缀k和后缀k,可以交换任意次数,看最后是否能使两个数组相等 ...
随机推荐
- 2021升级版微服务教程5—通过IDEA运行多个项目实例「模拟集群」
2021升级版SpringCloud教程从入门到实战精通「H版&alibaba&链路追踪&日志&事务&锁」 教程全目录「含视频」:https://gitee.c ...
- Mac安装Go语言
正文 安装 安装我们使用 HomeBrew ,其使用方法详见我的上一篇博文 brew install go 配置环境变量 Go1.3及以后版本跳过以下步骤 进入变量文件 cd ~ vim .bash_ ...
- 【栈和队列】2、栈的基本实现 - Java
简单记录 - bobo老师的玩转算法系列–玩转数据结构 - 栈和队列 栈的实现 Stack<E> void push(E) E pop() E peek() int getSize() b ...
- 【Linux】E297: Write error in swap file 解决办法
今天登陆到服务器上,发现通过vi 打开文件就会报错: E297: Write error in swap file E303: Unable to open swap file for "c ...
- 【ORACLE错误】SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
执行set autotrace traceonly的时候,报错 SQL> set autotrace traceonly SP2-0618: Cannot find the Session Id ...
- mysql查看修改参数
1.查看参数 show variables like '%timeout%'; 2.修改参数 会话级别修改: set session innodb_lock_wait_timeout=50; 对当前会 ...
- mysql 1449 : The user specified as a definer ('usertest'@'%') does not exist 解决方法 (grant 授予权限)
从服务器上迁移数据库到本地localhost 执行 函数 时报错, mysql 1449 : The user specified as a definer ('usertest'@'%') do ...
- Python 日志打印之自定义logger handler
日志打印之自定义logger handler By:授客 QQ:1033553122 #实践环境 WIN 10 Python 3.6.5 #实践代码 handler.py #!/usr/bin/env ...
- Amazon Selling Partner API 开发笔记
资料整理 1.sp-api介绍:https://developer.amazonservices.com/ 2.github文档:https://github.com/amzn/selling-par ...
- status http status code 状态码
RFC 6585 - Additional HTTP Status Codes https://tools.ietf.org/html/rfc6585 https://developer.mozill ...