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;

}


 

目录
相关文章
|
4月前
flag_in_your_hand
flag_in_your_hand
24 0
|
7月前
|
机器学习/深度学习 人工智能
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!
19 0
|
7月前
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)
18 0
HDOJ 1095 A+B for Input-Output Practice (VII)
HDOJ 1095 A+B for Input-Output Practice (VII)
79 0
HDOJ 1096 A+B for Input-Output Practice (VIII)
HDOJ 1096 A+B for Input-Output Practice (VIII)
78 0
ng-repeat part1 - how UI is rendered from {{name}} to actual value
ng-repeat part1 - how UI is rendered from {{name}} to actual value
ng-repeat part1 - how UI is rendered from {{name}} to actual value