CF920C Swap Adjacent Elements 贪心
我也不知道该说啥,水就是了~
code:
#include <bits/stdc++.h>
#define N 300004
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
char S[N];
int a[N],s[N];
int main()
{
// setIO("input");
int i,j,n,flag=0;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&a[i]);
scanf("%s",S+1);
for(i=1;i<n;++i)
{
if(S[i]=='0') s[i]=0; else s[i]=1;
s[i]+=s[i-1];
}
for(i=1;i<=n;++i)
{
if(a[i]>i)
{
int dis=a[i]-i;
if(s[a[i]-1]-s[i-1]!=dis) flag=1;
}
if(a[i]<i)
{
int dis=i-a[i];
if(s[i-1]-s[a[i]-1]!=dis) flag=1;
}
}
if(flag) printf("NO\n");
else printf("YES\n");
return 0;
}
CF920C Swap Adjacent Elements 贪心的更多相关文章
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
- CodeForces - 920C Swap Adjacent Elements
传送门:点我 You have an array a consisting of n integers. Each integer from 1 to n appears exactly once i ...
- Swap Adjacent Elements
You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this ...
- 【Educational Codeforces Round 37 C】 Swap Adjacent Elements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然l..r这一段连续的1可以把l..r+1变成有序的. 那么就把所有的连续1段变成有序的就好. 看看最后是不是升序即可. [代码] ...
- CF-920C-Swap Adjacent Elements 贪心
题意 给你一个1-n的排列. 并给你一个字符串——其中用0和1表示对应数列中的位置上的值可不可以和后面相邻的数交换. 判断该数列能否在限制中交换为不降序数列. 思路 由于刚学了树状数组,一开始以为是用 ...
- PTA 1067 Sort with Swap(0, i) (贪心)
题目链接:1067 Sort with Swap(0, i) (25 分) 题意 给定长度为 \(n\) 的排列,如果每次只能把某个数和第 \(0\) 个数交换,那么要使排列是升序的最少需要交换几次. ...
- PAT甲题题解-1067. Sort with Swap(0,*) (25)-贪心算法
贪心算法 次数最少的方法,即:1.每次都将0与应该放置在0位置的数字交换即可.2.如果0处在自己位置上,那么随便与一个不处在自己位置上的数交换,重复上一步即可.拿样例举例: 0 1 2 3 4 5 ...
- AGC028E High Elements 贪心、DP、线段树
传送门 看到要求"字典序最小"的方案,一个很直观的想法是按位贪心,那么我们需要check的就是当某一个数放在了第一个序列之后是否还存在方案. 假设当前两个序列的最大值和前缀最值数量 ...
- [Swift]LeetCode777. 在LR字符串中交换相邻字符 | Swap Adjacent in LR String
In a string composed of 'L', 'R', and 'X'characters, like "RXXLRXRXL", a move consists of ...
随机推荐
- MogileFS操作指令
使用mogtool来操作文件 加入文件:mogtool inject <file_name> <key_name> --trackers=192.168.1.106:7001 ...
- PAT-1003 Emergency (25 分) 最短路最大点权+求相同cost最短路的数量
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- [Vue]避免 v-if 和 v-for 用在同一个元素上
一般我们在两种常见的情况下会倾向于这样做: 情形1:为了过滤一个列表中的项目 (比如 v-for="user in users" v-if="user.isActive& ...
- LeetCode 1103. Distribute Candies to People
1103. Distribute Candies to People(分糖果||) 链接:https://leetcode-cn.com/problems/distribute-candies-to- ...
- Python实现定时执行任务的三种方式简单示例
本文实例讲述了Python实现定时执行任务的三种方式.分享给大家供大家参考,具体如下: 1.定时任务代码 import time,os,sched schedule = sched.scheduler ...
- 原生js上传图片遇到的坑(axios封装)
后台给我写了一个上传图片的接口,自己用form表单测试成功 接口可以正常跳转 测试的代码: <!doctype html> <html lang="en"> ...
- JavaScript指定日期格式化
formatDataToString:function (dates, formats) { var o = { "M+": dates.getMonth() + 1, //月份 ...
- Java基础加强-代理
/*代理*//*代理的概念与作用*/ 代理过程架构 客户端Client原来直接调用的是Target目标类 使用代理后,现在让客户端不要调用Target,调用代理类Proxy,代理类Proxy和目标类T ...
- maven项目下pom.xml依赖报错
百度了好几次,说是在本地仓库下少plugin,但是找了之后,发现并没有少呀
- oracle通过一个字段分组,取另一个字段的最大值
select * from bdcdj.lqentry1 a where 顺序号 in (select max(顺序号) from bdcdj.lqentry1 b WHERE b.archival ...