Codeforces Round #624 (Div.3)

题目地址:https://codeforces.ml/contest/1311

B题:WeirdSort

题意:给出含有n个元素的数组a,和m个元素的数组p,p中元素表示可调换(p=[3,2]表示a中下标为3和下标为3+1的元素可调换,2和2+1可调换),问能否使得原数组成为非降序数组

思路:暴力,模仿冒泡排序

AC代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 2e5+;
int main()
{ int T;
cin>>T;
while(T--)
{
int node[];//记录原数组
int f[];//记录可调换下标
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++) cin>>node[i];
for(int i=;i<=m;i++) cin>>f[i]; for(int i=;i<=n;i++)
{ for(int j = ;j<=m;j++)
{
if(node[f[j]]>node[f[j]+])//如果前边的大于后面的则调换
swap(node[f[j]],node[f[j]+]);
}
}
// 所有可调换位置均以成为非递减
if(is_sorted(node+,node++n)) // 判断是否和升序排序后的数组相同
puts("YES");
else
puts("NO");
}
return ;
}

C题:Perform the Combo

题意:判断字母出现次数,给定字符串,和m个数记录在数组中,记录字母出现次数时每次从第1位开始,直到数组中所给数又重新开始记录,最后在从第一位到最后一位记录一遍,输出每个字母出现的次数

思路:如果按照题意一一模拟遍历发现会超时,因为所给数组中的数可能相同,多次做相同遍历,浪费时间 可以用前缀和 * 相同数字出现次数

AC代码:

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 2e5+;
int main()
{ int T;
cin>>T;
while(T--)
{
int n,m;
string s;
int ans[]={};//每个字母出现次数
int sum[]={};//前缀和
int node[maxn]={};
cin>>n>>m>>s;
for(int i=;i<m;i++)
{
int t;
cin>>t;
node[t]++;//记录每个数的出现次数
} for(int i=;i<s.length();i++)
{
ans[s[i]-'a']++;
sum[s[i]-'a']++;
if(node[i+])//node中数是从1开始的而ans的下标是从0开始的
{
for(int j=;j<;j++)
{
ans[j]+= sum[j]*node[i+];
}
}
} for(int i=;i<;i++)
{
cout<<ans[i];
if(i!=) cout<<" ";
}
puts("");
}
return ;
}

Codeforces Round #624 (Div. 3)(题解)的更多相关文章

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

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

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. Update(Stage4):spark_rdd算子:第2节 RDD_action算子_分区_缓存:缓存、Checkpoint

    4. 缓存 概要 缓存的意义 缓存相关的 API 缓存级别以及最佳实践 4.1. 缓存的意义 使用缓存的原因 - 多次使用 RDD 需求: 在日志文件中找到访问次数最少的 IP 和访问次数最多的 IP ...

  2. linux Shell(待学)

    2. Shell 2.1 简介 shell脚本执行方式Shell 是一个用 C 语言编写的程序,通过 Shell 用户可以访问操作系统内核服务.它类似于 DOS 下的 command 和后来的 cmd ...

  3. Math 用法

    console.log(Math.abs(-5)) 取绝对值 console.log(Math.round(5.1)) 取四舍五入 5.5 为中间值 取5 console.log(Math.ceil( ...

  4. mysql 官方读写分离方案

    mysql 8.0 集群模式下的自动读写分离方案 问题 多主模式下的组复制,看起来挺好,起始问题和限制很多.而且中断一个复制就无法配置了 多主模式下,innodbcluster 等于是无用的,不需要自 ...

  5. BlockingQueue的几个实现分析

    ArrayBlockingQueue 底层以数组的结构存放队列元素,容量大小不可改变. 先看下变量: items:数组,用于存放队列中的元素 takeIndex:获取元素的索引位置 putIndex: ...

  6. linux 添加与修改用户归属组

    参考资源:https://cnzhx.net/blog/linux-add-user-to-group/ 一:已存在的用户 1.要以root进行登录 2.打开终端 3.修改分组 usermod -a ...

  7. tensorflow版helloworld---拟合线性函数的k和b(02-4)

    给不明白深度学习能干什么的同学,感受下深度学习的power import tensorflow as tf import numpy as np #使用numpy生成100个随机点 x_data=np ...

  8. 02-06Android学习进度报告六

    今天学习了关于Android开发中常用的两个知识,即对话框和悬浮框. 首先我学习了对话框的基本使用流程 Step 1:创建AlertDialog.Builder对象: Step 2:调用setIcon ...

  9. 学习笔记(14)- SQuAD的数据格式

    BERT模型完成问答任务的时候,需要数据格式为SQuAD形式. 有2个版本,1.1和2.0

  10. Systemverilog for design 笔记(六)

    转载请标明出处 第一章 有限状态机建模(FSM,finite state machine) 1.1.    使用枚举类型建立状态机模型 l  三过程块建模风格:三个过程块分别实现: a.状态转换(al ...