CF634A Island Puzzle 题解

分析

由于我们仅能移动 \(0\),所以其它数字的相对顺序较原来应该是不变的,所以我们从环中删除 \(0\) 再判断相对位置即可。

还有需要注意的是本题是一个环,找到末尾需要用取模操作回到开头继续比较。

示例代码

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
int aa,bb;
for(int i=0;i<n-1;i++)
{
cin>>a[i];
if(a[i]==0)i--;
if(a[i]==1)aa=i;
}
for(int i=0;i<n-1;i++)
{
cin>>b[i];
if(b[i]==0)i--;
if(b[i]==1)bb=i;
}
// for(int i=0;i<n;i++)cout<<a[i]<<" ";
// cout<<endl;
// for(int i=0;i<n;i++)cout<<b[i]<<" ";
// cout<<endl;
bool flag=1;
for(int i=0;i<n-1;i++)
{
// cout<<a[(i+aa)%(n-1)]<<" "<<b[(i+bb)%(n-1)]<<endl;
if(a[(i+aa)%(n-1)]!=b[(i+bb)%(n-1)])
{
flag=0;
break;
}
}
if(flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}

题解:CF634A Island Puzzle的更多相关文章

  1. codeforce B Island Puzzle

    B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. codeforces A. Orchestra B. Island Puzzle

    A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. CF 634A Island Puzzle

    A. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. codeforces B. Island Puzzle

    B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)

    暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...

  6. 冬训 day2

    模拟枚举... A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B) 暴力枚举即可,但是直接手动暴力会非 ...

  7. 算法与数据结构基础 - 广度优先搜索(BFS)

    BFS基础 广度优先搜索(Breadth First Search)用于按离始节点距离.由近到远渐次访问图的节点,可视化BFS 通常使用队列(queue)结构模拟BFS过程,关于queue见:算法与数 ...

  8. 贪心/构造/DP 杂题选做Ⅱ

    由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...

  9. 【题解】Puzzle [Uva1399]

    [题解]Puzzle [Uva1399] 传送门:\(\text{Puzzle [Uva1399]}\) [题目描述] 给定 \(m\) 和 \(n\),表示有 \(m\) 种不同的字符(大写字母\( ...

  10. 题解 CF540D 【Bad Luck Island】

    既然没有大佬写题解那本蒟蒻就厚颜无耻地写(水)一(经)下(验)吧 题目要求算出个种人单独留下的存活率 因为n,m,p的范围极小, 那么就可以方便地设3位dp状态dp[i][j][k]表示剩余i个石头, ...

随机推荐

  1. WM_ERASEBKGND

    WM_ERASEBKGND是在当窗口背景必须被擦除时 (例如,窗口的移动,窗口的大小的改变)才发送. 当窗口的一部分无效需要重绘时发送此消息. #define WM_ERASEBKGND 0x0014 ...

  2. 常用 DNS 查询速度测试

    测试工具 DNS-Benchmark | GitHub 总结 进过多轮测试,我认为: 223.5.5.5 和 223.6.6.6 平均响应时间最短(223.5.5.5 在教育网内疑似无法连通) 114 ...

  3. Coursera, Deep Learning 5, Sequence Models, week4, Transformer Network

    self-attention multi-head attention

  4. k8s 知识

    命令 Pod 管理 kubectl get pods 查看pod在哪个node上 kubectl get pods -o wide kubectl describe pod pod_name 创建新的 ...

  5. git 乱操作

    https://www.cnblogs.com/qybk/p/10880901.html 错误提示一样,只是我是在我自己的分支(xxx_dev)里.所以以下要改一下. git pull origin ...

  6. Angular Material 18+ 高级教程 – CDK Table

    前言 CDK Table 是 Angular Material 对 <table> 的抽象 (无 styles) 封装. 无 styles 的 table 有什么好封装的呢? CDK Ta ...

  7. Time Zone, Leap Year, Date Format, Epoch Time 时区, 闰年, 日期格式

    前言 以前有写过一篇了, 但很乱, 这篇就作为它的整理版吧. Leap Year 闰年 闰年是指那些有 366 天, 二月份有 29号 的年份. 比如 2020年 有 2月29日, 所以 2020 就 ...

  8. Linux板子与ubuntu交互,NFS配置

    第0步:保证你的ubuntu能上网,可以选择NAT方式让ubuntu上网. 第一步:安装NFS服务 sudo apt-get install nfs-kernel-server portmap 第二步 ...

  9. React的useId,现在Vue3.5终于也有了!

    前言 React在很早之前的版本中加了useId,用于生成唯一ID.在Vue3.5版本中,终于也有了期待已久的useId.这篇文章来带你搞清楚useId有哪些应用场景,以及他是如何实现的. 关注公众号 ...

  10. 暑假集训PVZ提高模拟9

    没关 exe 让这货挂了一天 UPD:又挂了一晚上,现在被我正义制裁了 A.大众点评 交互红题啊,交互会写,但是忘记判 \(n=1\) 了 这个题交互库函数实现起来还是挺简单的,我 Windows 不 ...