8 VC Venture Cup 2016-Final Round(Div.2 Edition)B.sland Pzle水題

2269 ワード

B.sland Pzle
テーマ接続:
http://www.codeforces.com/contest/635/problem/B
Description
A remote island islalalalalalalaland 1 through n.Bidirectoral bridges connect the islands to form a simple cycle-a bridge connects s islands 1 and 2,islands 2 and 3,and so on,and soon,and addititititititititititititititititititionnalalalalalalalalaladddddddbriccccccccccccccccccccccccccccccccccccccccccccccccccccccccccmmmmmmhas a fragrail、uniquely colored stature currently held on the pedestal.The remaning 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 chose an is directly adjacent to the island containgy pedestal.The the n、they paint starradcant
Determine if it is possible for the islander to arrange the statues in the desired order.
Input
The first line contains a single integer n(2̵≦𔎅n̵n≦𔎅200𔎅000)−the total number of islands.
The second line contains n space-separated integers ai(0̵≦𔎅ai𔎄n𔎅-𔎅1)-the stature e currently placd the i-th island.If the the the the the the the
The third line contains n space-separated integers bi(0̵≦𔎅bi𔎅≦𔎄n𔎅-𔎄1)−the desired status.Onagain,bistine 820
Output
Print「YES」if the rearrangement can be done in the existing network,and「NO」others wise.
Sample Input
3 1 0 2 2 0 1
Sample Output
YES
ベント
題意
スタートを切ってあげます。そしてこのスタートラインの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");

}