CF Round 8VC (B. Island Puzzle)判断两个环相等
2016-03-02 19:19
387 查看
题意:给出长度位n 的两个数串,每个串都是一个环即首尾看作是相连的。
问:第一个串是否可以可以通过移动一定的步数,变成第二个数串。
Examples
input
3
1 0 2
2 0 1
output
YES
input
2
1 0
0 1
output
YES
input
4
1 2 3 0
0 3 2 1
output
NO
分析:题中的0是关键点,由于是环,把数组中的0去掉之后,问题就变为判断两个环是否相等。
问:第一个串是否可以可以通过移动一定的步数,变成第二个数串。
Examples
input
3
1 0 2
2 0 1
output
YES
input
2
1 0
0 1
output
YES
input
4
1 2 3 0
0 3 2 1
output
NO
分析:题中的0是关键点,由于是环,把数组中的0去掉之后,问题就变为判断两个环是否相等。
#include<bits/stdc++.h> using namespace std; #define N 200005 int main() { int n; int a ,b ; scanf("%d",&n); for(int i=0;i<n-1;i++)//去除0,长度变为n-1 { scanf("%d",a+i); if(a[i]==0) i--; } for(int i=0;i<n-1;i++) { scanf("%d",b+i); if(b[i]==0) i--; } int ii,jj; for(int i=0;i<n-1;i++) if(a[i]==b[0]){ ii=i; break; } int i; for(i=0;i<n-1;i++)//判断两个环是否相等 if(a[(ii+i)%(n-1)]!=b[i]) break; if(i!=n-1) printf("NO\n"); else printf("YES\n"); return 0; }
相关文章推荐
- Valid Anagram--JavaScript
- 宝宝去了幼儿园不爱说话怎么办?
- hibernate笔记--组合主键映射方法
- 多看看他们
- FTP 实践
- shell学习
- Centos7源码安装mysql
- Qt之QHeaderView自定义排序(QSortFilterProxyModel)
- Android之进程与线程的讲解
- Qt之QHeaderView自定义排序(QSortFilterProxyModel)
- Configure Oracle GoldenGate for Oracle to Oracle Database Synchronization
- 【Hello,world 】如果你说“我要先学习一下再开始做”那么你永远不会真正开始。
- 移动web初体验
- codeforces 632B B. Alice, Bob, Two Teams(暴力)
- javascript函数
- RHEL 4.7下的Oracle 10g RAC到单实例的单向同步
- WebView的使用
- 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis
- HDU3294 Girls' research
- 重建二叉树