cf 153.div2 D. Playing with Permutations

简介:

D. Playing with Permutations

 

     比赛的时候一直没看懂题,后来看了下,其实很简单,就是给你一个变换序列q ,有两种变换1和2,1就是令Pi=Pqi,2则相反,互为逆变换,所以只要单独求出每种变换要多少少次,即可判断出来能否成功变换。

 

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#define INF 1E9
using namespace std;
int q[100];
string aim="";
char p[105];
int i,n;
string c1(string s)
{
    for(i=0;i<n;i++)
      p[i]=s[q[i]];
    return p;
}
string c2(string s)
{
    for(i=0;i<n;i++)
      p[q[i]]=s[i];
    return p;
}
string now="",nn;
int k1,k2;
int main()
{
    int k,t,lvl;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&q[i]);
        q[i]--;
    }
    for(i=0;i<n;i++)
    {
        scanf("%d",&t);
        aim.push_back(t);
        now.push_back(i+1);
    }
    nn=now;
    for(k1=0;k1<=k&&now!=aim;now=c1(now),k1++);
    for(k2=0;k2<=k&&nn!=aim;nn=c2(nn),k2++);
    if((k-k2)%2&&(k-k1)%2||(k>1&&k1==1&&k2==1)||!k1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

}


 

目录
相关文章
flag_in_your_hand
flag_in_your_hand
50 0
|
机器学习/深度学习 人工智能
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)B. Take Your Places!
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)B. Take Your Places!
43 0
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)
55 0
1006.Funny Function
Problem Description Function Fx,yF_{x,y}satisfies: F1,1=F1,2=1F_{1,1}=F_{1,2}=1F1,i=F1,i−1...
1052 0