B - WeirdSort
B - WeirdSort


思路:经过认真的审题,你会发现,这只是个冒泡的变形,我们建立两个数组,然后用一个数组里面的数字确定位置,然后冒泡就行了。最后抖机灵用了个is_sorted,判断数组里面数字的排列顺序。
代码:
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std; int a[105], b[105]; int main(){
int i, j;
int t;
scanf("%d", &t);
while (t--){
int n, m;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < m; i++)
scanf("%d", &b[i]);
for (i = 0; i < n; i++){
for (j = 0; j < m; j++){
if (a[b[j]-1]>a[b[j]])
swap(a[b[j]-1], a[b[j]]);
}
}
if (is_sorted(a , a + n))
printf("YES\n"); else
printf("NO\n");
} return 0;
}
B - WeirdSort的更多相关文章
- [CF1311B] WeirdSort
Solution 按照 \(p[i]\) 进行分段,如果某个 \(k\) 不存在 \(p[i]=k\),那么就把 \(i,i+1\) 分割开 处理出每一段的左端点和右端点 进而处理出每段的最小值和最大 ...
- Codeforces Round #624 (Div. 3) B. WeirdSort(排序)
output standard output You are given an array aa of length nn . You are also given a set of distinct ...
- Codeforce1311B. WeirdSort (冒泡排序)
You are given an array a of length n. You are also given a set of distinct positions p1,p2,-,pm, whe ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #624 (Div. 3)(题解)
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...
随机推荐
- ES5 绑定 this 的方法
this的动态切换,固然为 JavaScript 创造了巨大的灵活性,但也使得编程变得困难和模糊.有时,需要把this固定下来,避免出现意想不到的情况.JavaScript 提供了call.apply ...
- Django中的app模型细节TypeError: __init__() missing 1 required positional argument: 'on_delete' 解决办法
TypeError: init() missing 1 required positional argument: 'on_delete' 解决办法 当执行应用app模型迁移时: python man ...
- java中indexOf()获取指定次数的下标
indexOf() :指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置 Java中提供了四中查找方法: int indexOf(String str) 返回第一 ...
- myForEach
Array.prototype.myForEach = function (callback, thisArg = undefined) { if (typeof callback !== 'func ...
- 请求浏览器重新加载数据/返回前端Json 数据
右键检查 seeting network dissable cache 勾选上 ================================== from django.http import J ...
- linux 安装goland
一.Goland-IDEA 2020.3.2安装 1 下载 下载GoLand https://www.jetbrains.com/go/download/#section=linux 2 安装Gola ...
- KMS服务器 激活win 和 office
环境:Debian 9.5 (Google Cloud) 切换到root用户:sudo su wget --no-check-certificate https://github.com/teddys ...
- (K8s学习笔记六)Pod的调度
RC(ReplicationController)只能选择一个标签,RS(ReplicaSet)可选择多个标签,例如APPTest发布了v1和v2两个版本,并希望副本数为3,可同时包含v1和v2两个版 ...
- R7-1 求10个点到原点的距离和
R7-1 求10个点到原点的距离和 分数 15 全屏浏览题目 切换布局 作者 张高燕 单位 浙大城市学院 求10个点到原点的距离和.输入10个点的坐标,计算并输出这些点到原点的距离和.定义函数dist ...
- cv::inRange
// 简单实现 cv::namedWindow("Example 2-3", cv::WINDOW_AUTOSIZE); cv::VideoCapture cap; cap.ope ...