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. mysql转国产数据库达梦随记

    记录一下转换的一些小坑. window环境 项目是springboot+ activiti6 + vue 第一步转移数据: mysql5.7  ---> 达梦7 这里使用dm的工具进行转换.发现 ...

  2. qt creator 常量中有换行符(转)

    这篇文章写于QT5.6的诞生,它是QT5的第一个长期支持版.这也是QT5已成熟的里程碑. 我搭建的环境是:Win10+VS2015+QT5.6+QtCreator 在安装VS2015的时候,若是用Qt ...

  3. 人为提升服务器CPU、内存、硬盘使用率

    一.CPU使用率 vikyd/go-cpu-load: Generate CPU load on Windows/Linux/Mac (github.com) 所有CPU核心负载30%运行10秒钟 . ...

  4. socket简记-消息格式

    1 原理 1.1 数据格式 Packet header + Application body + Packet Tail 本协议中数据字节序为Little endian(超过一个字节的数据类型在内存中 ...

  5. springboot gradle 集成流程引擎activiti

    buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } } dep ...

  6. GO 语言中的 sync Map

    为什么需要 sync map go 语言之所以引入 sync.Map主要是因为GO 语言自带的 map 是线程不安全的.只能保证并发的读,但是不能保证并发的写. 看下面的例子: func main() ...

  7. 转载-分享一个Ubuntu20.04安装以及中文教程

    https://blog.csdn.net/weixin_45912291/article/details/108901106 https://www.cnblogs.com/libotaoer/p/ ...

  8. PostgreSQL-14 安装配置-wsl_v1_ubuntu22.04

    环境准备 pgAdmin: Cisco2022 postgrep数据库: postgres: Postgres_2023 install https://learn.microsoft.com/en- ...

  9. 2023Hgame

    2023Hgame Shared Diary 源代码先放一下 const express = require('express'); const bodyParser = require('body- ...

  10. 树莓派 Zero W 安装 apache2 + php

    ※ 树莓派Zero W ,默认 hostname为 raspberrypi ,通过USB网络方式登陆时,修改hostname后,登录主机名要随之变化. ① ssh pi@raspberrypi 更新系 ...