日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Playing with Permutations(CF-252D)

發(fā)布時間:2025/3/17 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Playing with Permutations(CF-252D) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Problem Description

Little Petya likes permutations a lot. Recently his mom has presented him permutation q1,?q2,?...,?qn of length n.

A permutation a of length n is a sequence of integers a1,?a2,?...,?an (1?≤?ai?≤?n), all integers there are distinct.

There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length n. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:

  • Before the beginning of the game Petya writes permutation 1,?2,?...,?n on the blackboard. After that Petya makes exactly k moves, which are described below.
  • During a move Petya tosses a coin. If the coin shows heads, he performs point:1, if the coin shows tails, he performs point 2.
    1)1——Let's assume that the board contains permutation p1,?p2,?...,?pn at the given moment. Then Petya removes the written permutation p from the board and writes another one instead: pq1,?pq2,?...,?pqn. In other words, Petya applies permutation q (which he has got from his mother) to permutation p.
    2)All actions are similar to point 1, except that Petya writes permutation t on the board, such that: tqi?=?pi for all i from 1 to n. In other words, Petya applies a permutation that is inverse to q to permutation p.

We know that after the k-th move the board contained Masha's permutation s1,?s2,?...,?sn. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the k-th move. Note that the game has exactly k moves, that is, throughout the game the coin was tossed exactly k times.

Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.

Input

The first line contains two integers n and k (1?≤?n,?k?≤?100). The second line contains n space-separated integers q1,?q2,?...,?qn (1?≤?qi?≤?n) — the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format.

It is guaranteed that the given sequences q and s are correct permutations.

Output

If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).

Examples

Input

4 1
2 3 4 1
1 2 3 4

Output

NO

Input

4 1
4 3 1 2
3 4 2 1

Output

YES

Input

4 3
4 3 1 2
3 4 2 1

Output

YES

Input

4 2
4 3 1 2
2 1 4 3

Output

YES

Input

4 1
4 3 1 2
2 1 4 3

Output

NO

Note

In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed.

In the second sample the described situation is possible, in case if after we toss a coin, we get tails.

In the third sample the possible coin tossing sequence is: heads-tails-tails.

In the fourth sample the possible coin tossing sequence is: heads-heads.

題意:給出兩個長度為 n 的序列 q、s,問通過 p[q[i]]=p[i]、p[i]=p[q[i]] 這兩種變換,使得 k 次變換后 p 序列變?yōu)?s 序列,且變換過程中,p 序列不能與 s 序列相同

思路:可以看出,給出的兩個操作是相反的,也就是說,兩種變換分別做一次后能夠相消除,因此只需要計算出序列 p 通過第一種變換要多少次,第二種變換要多少次,然后分類討論即可

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define EPS 1e-9 #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long #define Pair pair<int,int> const int MOD = 1E9+7; const int N = 1000+5; const int dx[] = {-1,1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std;int op1[N],op2[N]; int q[N],s[N]; int main() {int n,k;scanf("%d%d",&n,&k);for(int i=1; i<=n; i++)scanf("%d",&q[i]);for(int i=1; i<=n; i++)scanf("%d",&s[i]);for(int i=1; i<=n; i++)op1[i]=op2[i]=i;int numP=0;while(numP<=k) {bool flag=1;for(int i=1; i<=n; i++) {if(op1[i]!=s[i])flag=0;}if(flag)break;for(int i=1; i<=n; i++)op1[i]=op2[q[i]];for(int i=1; i<=n; i++)op2[i]=op1[i];numP++;}for(int i=1; i<=n; i++)op1[i]=op2[i]=i;int numS=0;while(numS<=k) {bool flag=1;for(int i=1; i<=n; i++) {if(op1[i]!=s[i])flag=0;}if(flag)break;for(int i=1; i<=n; i++)op1[q[i]]=op2[i];for(int i=1; i<=n; i++)op2[i]=op1[i];numS++;}if(numP==0||numS==0)printf("NO\n");else if(k==1&&(numP==1||numS==1))printf("YES\n");else if(k!=1&&numP==1&&numS==1)printf("NO\n");else if(numP==k+1&&numS==k+1)printf("NO\n");else if((numP-k)%2==0&&numP<=k)printf("YES\n");else if((numS-k)%2==0&&numS<=k)printf("YES\n");elseprintf("NO\n");return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的Playing with Permutations(CF-252D)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 999国产精品视频免费 | 国产美女视频免费观看下载软件 | 精品在线播放 | 四虎av在线播放 | 亚洲第一在线 | 免费看日韩毛片 | 国产高清一区二区 | 91精品视频在线看 | 午夜在线一区二区三区 | 亚洲毛片在线观看 | 韩国91视频| 欧美午夜精品久久久久免费视 | jizz久久 | 美女张开腿露出尿口 | 91av视频在线播放 | 成人精品视频在线播放 | 国产日韩欧美精品一区 | 国产成人一区 | 美女久久视频 | 免费av导航 | 人人九九精 | 给我看高清的视频在线观看 | 黄在线视频 | 精品国产一级片 | 亚洲精品粉嫩小泬 | bbbbbbbbb毛片大片按摩 | 黄色av网站在线免费观看 | av大帝| 老男人av| 91中文字幕在线观看 | zzjj国产精品一区二区 | 亚洲伊人网站 | 国产精品高清无码 | 一区二区三区精品免费视频 | 日本精品免费一区二区三区 | 久久精品人妻一区二区 | 久久九九久精品国产免费直播 | www毛片 | 色伊人影院 | 久久精品国产一区二区三区 | 亚洲国产中文字幕在线观看 | 免费观看全黄做爰的视频 | 人妻少妇被猛烈进入中文字幕 | av在线播放观看 | 丰满少妇中文字幕 | 奇米影视狠狠 | 自拍偷拍另类 | 欧美草逼视频 | 99精品欧美 | 国产又大又黑又粗免费视频 | 朱竹清到爽高潮痉挛 | 亚洲一区二区国产精品 | 老熟妇仑乱视频一区二区 | aaaaa级片 | 114国产精品久久免费观看 | 中文字幕一区二区不卡 | 久久久www成人免费精品 | 午夜福利三级理论电影 | 国产女女调教女同 | 亚洲精华国产精华精华液网站 | 强迫凌虐淫辱の牝奴在线观看 | 国产免费www| 亚洲av毛片成人精品 | 最新av在线播放 | 神马午夜一区 | 青青草原国产视频 | 久久av无码精品人妻系列试探 | 天天舔天天爱 | 在线高清观看免费观看 | 青青草原一区二区 | 国产一级淫片免费 | 波多野结衣视频在线 | 日韩精品一区二区亚洲av | 欧美一区二区三区黄片 | 这里只有精品国产 | 精品国产99久久久久久宅男i | 黄色片免费在线观看 | 亚洲精品字幕 | 91高清在线免费观看 | 亚洲精品无码不卡在线播he | 天堂在线视频免费观看 | 少妇精品视频 | 欧美午夜网 | 精品久久91| 日本阿v视频| 欧美久久久久久久久久 | 在线视频 一区二区 | 色av中文字幕 | 亚洲天堂男人的天堂 | 精品无码黑人又粗又大又长 | 亚洲成人一二区 | 成人涩涩网 | 欧洲人妻丰满av无码久久不卡 | 台湾佬成人中文网222vvv | av老司机福利 | 粉嫩久久99精品久久久久久夜 | 青青草原成人 | 伊人222成人综合网 亚洲日本中文 | sm捆绑调教视频 |