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的更多相关文章

  1. [CF1311B] WeirdSort

    Solution 按照 \(p[i]\) 进行分段,如果某个 \(k\) 不存在 \(p[i]=k\),那么就把 \(i,i+1\) 分割开 处理出每一段的左端点和右端点 进而处理出每段的最小值和最大 ...

  2. 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 ...

  3. Codeforce1311B. WeirdSort (冒泡排序)

    You are given an array a of length n. You are also given a set of distinct positions p1,p2,-,pm, whe ...

  4. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  5. Codeforces Round #624 (Div. 3)(题解)

    A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...

随机推荐

  1. 关于sqlyang 连接远程服务器 MySQL "1251-client does not support authentication..."的处理办法

    原因是在mysql8之前的版本中加密规则为mysql_native_password而在mysql8以后的加密规则为caching_sha2_password. 做如下修改 ALTER USER 'r ...

  2. 推荐2个可用于毕设的微信小程序

    智能垃圾回收小程序 下载: http://market.zhenzikj.com/detail/103.html 2. 通用答题小程序 下载http://market.zhenzikj.com/det ...

  3. python-djanggo 实现读取excel 表格在网页中展示

    1.准备读取数据 放到项目文件夹下 2.熟悉表结构 3.准备处理依赖库 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas o ...

  4. 事务与spring事务

    事务 事务的特性(ACID) 原子性(Atomicity): 标识将事务中所有的操作进行捆绑层一个不可分割的单元格,计对事务所有进行的数据库修改等操作,要么全部执行,要么就是全部失败隔离性(Isola ...

  5. C# VS2019修改工程名

    1.修改解决方案的名称:选择解决方案的名称,右键重命名即可 2.修改项目名称,方法同上,不再赘述 3.修改项目的程序集名称和默认命名空间:选择项目,右键属性,弹出如下对话框 4.替换项目或解决方案中的 ...

  6. 学习-Vue2-Vue实例-数据与方法-Object.freeze()

    Object.freeze(),会阻止修改现有的property,意味着响应系统无法再追踪变化 代码示例: <!DOCTYPE html> <html lang="en&q ...

  7. comment out one line in the file with sed

    sed -i "/test2/s/^/#/" test.log https://jaminzhang.github.io/linux/sed-command-usage-summa ...

  8. Cesium测量优化1

    简介:优化绘制点.线,面鼠标位置获取精度.支持3dties,gltf model,以及box等Geometry Entity上的位置拾取. 测试代码 <template> <div ...

  9. ubuntu启动盘制作

    转自https://www.cnblogs.com/silentdoer/p/13044305.html 1. 从Ubuntu官网http://cn.ubuntu.com/download/下载系统的 ...

  10. C#如何将光标定位到文本框末尾(最后一位)

    代码如下:private void Movetoend(){//让文本框获取焦点this.TextBox1.Focus();//设置光标的位置到文本尾this.TextBox1.Select(this ...