POJ-1721 CARDS 置换群分数幂运算
2013-04-13 19:28
211 查看
题目链接:http://poj.org/problem?id=1721
置换群的分数幂运算,分数幂运算考虑的是置换的合并,但这道题简化了很多,首先注意到“Alice first writes down all the numbers from 1 to N in some random order: a1, a2, ..., aN. Then she arranges the cards so that the position ai holds the card numbered ai+1, for every 1 <= i <= N-1, while the position aN holds the card numbered a1.”,即置换只有一个循环节且长度 l 为奇数,其次开放数为2。则有gcd(l,2)=1,即永远都只有一个循环节,直接模拟就可以了。
置换群的分数幂运算,分数幂运算考虑的是置换的合并,但这道题简化了很多,首先注意到“Alice first writes down all the numbers from 1 to N in some random order: a1, a2, ..., aN. Then she arranges the cards so that the position ai holds the card numbered ai+1, for every 1 <= i <= N-1, while the position aN holds the card numbered a1.”,即置换只有一个循环节且长度 l 为奇数,其次开放数为2。则有gcd(l,2)=1,即永远都只有一个循环节,直接模拟就可以了。
//STATUS:C++_AC_63MS_192KB #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<iostream> #include<string> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<map> using namespace std; #define LL __int64 #define pii pair<int,int> #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 const int N=1010,INF=0x3f3f3f3f,MOD=10000,STA=8000010; const LL LNF=0x3f3f3f3f3f3f3f3f; const double DNF=1e13; int T[2] ,vis ,C ; int n,s; int main() { // freopen("in.txt","r",stdin); int i,j,k,p,u,d; while(~scanf("%d%d",&n,&s)) { for(i=1;i<=n;i++) scanf("%d",&T[0][i]); p=1; while(s--){ mem(vis,0); for(i=1;i<=n;i++){ if(!vis[i]){ mem(vis,0); u=i;k=0; while(!vis[u]){ vis[u]=1; C[k++]=u; u=T[!p][u]; } d=(k+1)/2; for(j=0;j<k;j++){ T[p][C[j]]=C[(j+d)%k]; } } } p=!p; } p=!p; for(i=1;i<=n;i++) printf("%d\n",T[p][i]); } return 0; }
相关文章推荐
- poj 1721 CARDS(置换群)
- 【POJ】1721 - CARDS(置换群)
- poj 1721 CARDS 置换群
- POJ 1721-CARDS(置换群-单个循环置换幂运算 倒推)
- POJ 1721 - CARDS【置换群】
- poj 1721 CARDS (置换群)
- 【POJ 1721】CARDS(置换群)
- POJ 1721 CARDS(置换群)
- poj 1721 CARDS (置换群)
- poj 1721 CARDS(置换群的幂运算)
- poj 1721 CARDS 【置换群 】【求最小循环节 再由末序列 求 初序列】
- POJ 1721 CARDS <置换群>
- POJ 1721 CARDS (置换群)
- poj 3128 Leonardo's Notebook(置换群的分数幂运算)
- [POJ 1721]CARDS
- POJ 1721 CARDS
- POJ 1721 CARDS(置换+循环节)
- POJ 1721 CARDS(置换)
- poj 1721 CARDS 洗牌机
- poj1721 CARDS