生活随笔
收集整理的這篇文章主要介紹了
POJ - 1026 Cipher(置换群的幂)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接:點(diǎn)擊查看
題目大意:給出一個置換群,再給出數(shù)個字符串,每個字符串需要輸出執(zhí)行 k 次置換群后的答案
題目分析:置換群的 k 次冪,直接寫就行了
代碼:
?
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=210;int a[N];char str[N],ans[N];bool vis[N];int main()
{
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);int n;while(scanf("%d",&n)!=EOF&&n){for(int i=1;i<=n;i++)scanf("%d",a+i);memset(vis,false,sizeof(vis));vector<int>circle[N];int cnt=0;for(int i=1;i<=n;i++){if(vis[i])continue;cnt++;int pos=i;while(!vis[pos]){circle[cnt].push_back(pos);vis[pos]=true;pos=a[pos];}}int k;while(scanf("%d",&k)!=EOF&&k){gets(str);int len=strlen(str);for(int i=len;i<=n;i++)str[i]=' ';for(int i=1;i<=cnt;i++){int sz=circle[i].size();for(int j=0;j<sz;j++)ans[circle[i][(j+k)%sz]]=str[circle[i][j]];}ans[n+1]=0;puts(ans+1);}puts("");}return 0;
}
?
總結(jié)
以上是生活随笔為你收集整理的POJ - 1026 Cipher(置换群的幂)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。