8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题
B. sland Puzzle
题目连接:
http://www.codeforces.com/contest/635/problem/B
Description
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one of the islands has a fragile, uniquely colored statue currently held on the pedestal. The remaining island holds only an empty pedestal.
The islanders want to rearrange the statues in a new order. To do this, they repeat the following process: First, they choose an island directly adjacent to the island containing an empty pedestal. Then, they painstakingly carry the statue on this island across the adjoining bridge and place it on the empty pedestal.
Determine if it is possible for the islanders to arrange the statues in the desired order.
Input
The first line contains a single integer n (2 ≤ n ≤ 200 000) — the total number of islands.
The second line contains n space-separated integers ai (0 ≤ ai ≤ n - 1) — the statue currently placed on the i-th island. If ai = 0, then the island has no statue. It is guaranteed that the ai are distinct.
The third line contains n space-separated integers bi (0 ≤ bi ≤ n - 1) — the desired statues of the ith island. Once again, bi = 0 indicates the island desires no statue. It is guaranteed that the bi are distinct.
Output
Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise.
Sample Input
3
1 0 2
2 0 1
Sample Output
YES
Hint
题意
给你一个起始串,然后这个起始串的0可以和他的周围的数字交换位置(是环状的)
问你经过若干次交换之后
能否变成下面那个目标串
题解:
显然交换不改变相对位置
所以只要相对位置相同就好了
不相同就是NO
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int a[maxn],b[maxn],tot1,tot2;
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x;scanf("%d",&x);
if(x==0)continue;
a[tot1++]=x;
}
for(int i=0;i<n;i++)
{
int x;scanf("%d",&x);
if(x==0)continue;
b[tot2++]=x;
}
int s=0;
for(int i=0;i<tot2;i++)
{
if(b[i]==a[0])
{
s=i;
break;
}
}
for(int i=0;i<n-1;i++)
if(a[i]!=b[(i+s)%(n-1)])
return puts("NO");
return puts("YES");
}
8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题的更多相关文章
- 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 ...
- 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp
E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题
http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card
D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #de ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集
A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- C# 判断一个单链表是否有环及环长和环的入口点
1.为什么写这个随笔? 前几天参加一个电面,被问到这个问题,想总结一下. 2.为什么标题强调C#? 想在网上看看代码,却没找到C#版的,于是自己用C#实现一下. 一.解决问题的思路 1.一种比较耗空间 ...
- 访问dubbo没有权限,通过ip进行跳转服务器,并通过有权限服务器代理访问
#启动ip跳转 echo 1 > /proc/sys/net/ipv4/ip_forward vi /etc/sysctl.conf net.ipv4.ip_forward =1 sysctl ...
- git配置服务器版仓库
1.git 可以使用四种主要的协议来传输数据:本地传输,SSH 协议,Git 协议和 HTTP 协议.现在使用360同步盘同步一个网络的仓库管理. 2.查看设置好的360同步盘的文件 3.创建空的仓库 ...
- overflow属性在IE6下面失去效果
自然状态下 overflow的属性设置,本来是超过了一定的长度时会自动产生滚动条,但是在ie6下面失效了. 例如:原来的代码: .code{overflow-x:auto;margin:5px aut ...
- 23:django 信号(signal)
django包含了一个“信号分配器”使得当一些动作在框架的其他地方发生的时候,解耦的应用可以得到提醒.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者,这是特别有用的设计因为有些 ...
- ReentrantLock 分析
带着疑问去分析 ReentrantLock是如何实现锁管理的. ReentrantLock是如何实现重入的. ReentrantLock是如何实现公平锁与非公平锁. ReentantLock的公平锁为 ...
- FS Shell命令
HDFS命令基本格式 hadoop fs -cmd args hdfs dfs -cmd args cat hadoop fs -cat URI [URI .....] 将路径指定文件的内容输出到st ...
- Spring学习(二)——Spring中的AOP的初步理解
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...
- 修改sql server sa用户密码
EXEC sp_password NULL, 'NewPassword', 'Sa'
- Child Action
Control [ChildActionOnly] //只能用于Child Action public ActionResult Time() { return PartialView(Da ...