POJ 1026 Cipher(群置换) (待解决)
来源:互联网 发布:购买备案好的域名 编辑:程序博客网 时间:2024/05/16 01:30
题目链接:http://poj.org/problem?id=1026
题目大意:
给出1~n的置换序列, 然后给出一个整数k,和一个串
问置换k次后的串是什么样子的。
首先,给出的串的长度是小于等于n的,不足的位置要补上空格。
然后置换k次,不是直接就循环着置换,因为置换内的每个循环都是有一定长度的,如果超过这个长度的置换次数,必然会和前面的某个状态一样,所以对每个循环,如果长度为len,循环内的元素只需要置换k%len次即可。
开始用的结构体排序,结果果断超时
#include <iostream>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <cmath>using namespace std;struct TT{int num;char ch;}seq[210];bool cmp(TT a ,TT b ){return a.num<b.num;}int main(){ while(1){int i,n,sseq[210];scanf("%d",&n);for(i=0;i<n;i++){ // cout<<"..............."<<endl;scanf("%d",&seq[i].num);//输入次序sseq[i]=seq[i].num;} if(n==0) break;int k;while(cin>>k){//~scanf("%d",&k)){ if(k==0) break;char a[210],b[210],aaa;int j;memset(a,' ',sizeof(a));scanf("%c",&aaa);gets(a);if(strlen(a)<n)a[strlen(a)]=' ';for(j=0;j<n;j++)seq[j].ch=a[j];while(k--){///执行完之后k到底是多少sort(seq,seq+n,cmp);for(i=0;i<n;i++)seq[i].num=sseq[i];}for(i=0;i<n;i++) printf("%c",seq[i].ch); printf("\n");} } return 0;}
修改的代码(未完成)
#include <iostream>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <cmath>using namespace std;int main(){ while(1){int i,n,seq[210],test[210],testsq[210];scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&seq[i]);///输入次序testsq[i]=--seq[i];} if(n==0) break;int k;while(cin>>k){//~scanf("%d",&k)){ if(k==0) break;char a[210],aaa,testch[210];int j;memset(a,' ',sizeof(a));scanf("%c",&aaa); ///收取空格gets(a);if(strlen(a)<n)a[strlen(a)]=' ';for(i=0;i<n;i++) { int ccount=1; int road[210]; int aa=testsq[seq[i]]; testsq[seq[i]]=seq[i]; cout<<"***************************************"<<endl; while(1) ///查找周期 { if(aa==testsq[seq[i]])///两次相同的话 break; aa=seq[aa]; testsq[seq[i]]=seq[i]; road[i]=seq[i]; ccount++; } int temp=road[k%ccount]; testch[temp]=a[i]; }for(i=0;i<n;i++)printf("%c",testch[i]); printf("\n");} } return 0;}
0 0
- POJ 1026 Cipher(群置换) (待解决)
- 【POJ 1026】Cipher(置换群)
- 【POJ】1026 - Cipher(置换群)
- POJ 1026 Cipher (置换群)
- POJ 1026 Cipher(置换)
- poj 1026 Cipher(置换)
- POJ 1026 Cipher(置换)
- POJ 1026 Cipher(置换+循环节)
- poj 1026 Cipher(置换群循环节)
- POJ 1026 Cipher(置换群)循环节
- POJ 1026 Cipher 置换群
- poj-1026-Cipher-置换群
- POJ 1026 Cipher 置换群
- POJ 1026 Cipher (置换群)
- poj 1026 Cipher (置换群)
- poj 1026 Cipher (置换群)
- POJ 1026-Cipher(置换群)
- POJ 1026 - Cipher【置换群】
- 第14周拓展-二维数组旋转操作
- 浏览器兼容。js部分问题
- Codeforces Beta Round #4 (Div. 2 Only) C. Registration system
- 第一章——计算机网络概述
- poj 2553 The Bottom of a Graph(强连通)
- POJ 1026 Cipher(群置换) (待解决)
- 安装centos操作系统
- HDU2128Tempter of the Bone II(bfs+状态压缩)
- 不确定性原理的前世今生 · 数学篇(完)
- [jQuery]jQuery获取select文本的方法
- Android API 之Activity
- Android SDK Manager 无法下载 SDK 问题?
- POJ1163 The Triangle
- HDU 1055 Color a Tree