Codeforces Round #624 (Div. 3)(题解)
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)(题解)的更多相关文章
- Codeforces Round #624 (Div. 3)(题解)
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
随机推荐
- Es查询结果集默认是10000,更新设置
Es查询结果集默认是10000,结果集大小是int,最大为21亿左右 PUT _all/_settings?preserve_existing=true { "index.max_resul ...
- 于elasticsearch-rest-high-level-client 操作 Es
安装Java:要求JDK为1.8及以上版本. 创建阿里云Elasticsearch实例:实例版本要求大于等于elasticsearch-rest-high-level-client的版本.本文创建一个 ...
- redhat 7.6 iptables 配置
1.查看iptables默认表(filter) iptables -L -n 2.iptables 默认内链(filter)表三种: INPUT:处理进入防火墙的数据包 FORWARD:源自其他计算机 ...
- jsp格式化日期
1.先引入JSTL库 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> ...
- SpringBoot常用注解解析
@RestController 将返回的对象数据直接以 JSON 或 XML 形式写入 HTTP 响应(Response)中.绝大部分情况下都是直接以 JSON 形式返回给客户端,很少的情况下才会以 ...
- Mybatis之foreach用法----List、Array、Map三种类型遍历
在mybatis的xml文件中构建动态sql语句时,经常会用到标签遍历查询条件.特此记录下不同情况下书写方式!-------仅供大家参考------ 1. foreach元素的属性 collectio ...
- Plastic Bottle Manufacturer - What Is The Direction Of Plastic Bottles?
Plastic bottle manufacturers explain: protective packaging for cosmetic cleaning products requires b ...
- requests库GET
文档地址:http://docs.python-requests.org/zh_CN/latest/index.html import requests res = requests.get('htt ...
- tomcat启动报错failed to start component
严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catali ...
- 第3节 Scala中的模式匹配:1 - 5
7. 模式匹配和样例类 Scala有一个十分强大的模式匹配机制,可以应用到很多场合:如switch语句.类型检查等.并且Scala还提供了样例类,对模式匹配进行了优化,可以快速进行匹配. 7.1 ...