Description

剀剀和凡凡有N张牌(依次标号为1,2,……,N)和一台洗牌机。假设N是奇数。洗牌机的功能是进行如下的操作:对所有位置I(1≤I≤N),如果位置I上的牌是J,而且位置J上的牌是K,那么通过洗牌机后位置I上的牌将是K。

剀剀首先写下一个1~N的排列ai,在位置ai处放上数值ai+1的牌,得到的顺序x1, x2, ..., xN作为初始顺序。他把这种顺序排列的牌放入洗牌机洗牌S次,得到牌的顺序为p1, p2, ...,pN。现在,剀剀把牌的最后顺序和洗牌次数告诉凡凡,要凡凡猜出牌的最初顺序x1, x2, ..., xN。

Input

第一行为整数N和S。1≤N≤1000,1≤S≤1000。第二行为牌的最终顺序p1, p2, ..., pN。

Output

为一行,即牌的最初顺序x1, x2, ..., xN。

Sample Input

5 2

4

1

5

3

2

Sample Output

2

5

4

1

3


强行暴力,经过res个操作后会回到原顺序,最后做\(res-s\%res\)个操作即可

/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=1e3;
int x[N+10],y[N+10],tmp[N+10];
int n,s,res;
void Next(){
memcpy(tmp,x,sizeof(x));
for (int i=1;i<=n;i++) x[i]=tmp[x[i]];
}
bool check(){
for (int i=1;i<=n;i++) if (x[i]!=y[i]) return 0;
return 1;
}
int main(){
n=read(),s=read();
for (int i=1;i<=n;i++) x[i]=y[i]=read();
for (res=1;;res++){
Next();
if (check()) break;
}
res-=s%res;
for (;res;res--) Next();
for (int i=1;i<=n;i++) printf("%d\n",x[i]);
return 0;
}

[POJ1721]Cards的更多相关文章

  1. BZOJ 1004 【HNOI2008】 Cards

    题目链接:Cards 听说这道题是染色问题的入门题,于是就去学了一下\(Bunside\)引理和\(P\acute{o}lya\)定理(其实还是没有懂),回来写这道题. 由于题目中保证"任意 ...

  2. Codeforces Round #384 (Div. 2) 734E Vladik and cards

    E. Vladik and cards time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. bzoj 1004 Cards

    1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...

  4. codeforces 744C Hongcow Buys a Deck of Cards

    C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes in ...

  5. CF 204B Little Elephant and Cards

    题目链接: 传送门 Little Elephant and Cards time limit per test:2 second     memory limit per test:256 megab ...

  6. HDU 1535 Invitation Cards(最短路 spfa)

    题目链接: 传送门 Invitation Cards Time Limit: 5000MS     Memory Limit: 32768 K Description In the age of te ...

  7. Codeforces Round #227 (Div. 2) E. George and Cards set内二分+树状数组

    E. George and Cards   George is a cat, so he loves playing very much. Vitaly put n cards in a row in ...

  8. 队列 Soldier and Cards

    Soldier and Cards 题目: Description Two bored soldiers are playing card war. Their card deck consists ...

  9. [CareerCup] 18.2 Shuffle Cards 洗牌

    18.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle—in other words, each of ...

随机推荐

  1. 用"再生龙"Clonezilla 来克隆Linux系统

      上周公司买了5套高配置PC机来做测试用.上面要装好CentOS 加上一堆工具,有web的,数据库的,还有一些自己开发的工具.有些朋友肯定想,直接用kickstart不就行了,确实.kickstar ...

  2. JAVA_the user operation is waiting怎么办

    彻底解决 MyEclipse出现the user operation is waiting的问题   2011-05-31 10:32:30|  分类: 软件编程 |  标签:java  myecli ...

  3. EXCEPT(差集)集合运算

    在集合论中,集合A与B的差集(A-B)是由属于集合A,但不属于集合B的元素组成的集合.可以认为两个集合的差A-B就是从A中减去B中也属于A的元素. 在T-SQL中,集合之差是用EXCEPT集合运算实现 ...

  4. POJ1195 Mobile phones 【二维树状数组】

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14288   Accepted: 6642 De ...

  5. 《鸟哥的Linux私房菜-基础学习篇(第三版)》(六)

    第5章 首次登陆与在线求助man page        1. 首次登陆系统        首先谈了首次登陆CentOS 5.x界面.登陆选项中的会话是能够使用不同的图形界面来操作整个Linux系统. ...

  6. canvas鼠标点击划线

    今天学习了canvas,打算写一个鼠标划线的效果. <!DOCTYPE html> <html lang="en"> <head> <me ...

  7. PartialView中的页面重定向

    在MVC的每个action中,都可以指定一种返回页面的类型,可以是ActionResult,这表示返回的页面为view或者是一个PartialView,前台是一个全整页面,后台是页面的一部分. 在以A ...

  8. js实现加密(?!)

    <script src="yourUrl/md5.min.js"></script> 或者: <script src="http://cdn ...

  9. mysql05---游标

    drop procedure p12$ //删除存储过程 //游标cursor,一条sql对应n条资源,取出资源的接口/句柄就是cursor, 一条sql产生的n条结果不是一次性全部输出,而是返回一个 ...

  10. Magic Grid ComboBox JQuery 版

    在MagicCombo组件中嵌入Grid,以支持分页查找和跨页选取 ​ 1. ​2. [代码][JavaScript]单选示例代码     <script type="text/jav ...