poj 2369 Permutations(置换群)
来源:互联网 发布:科比淘宝店 编辑:程序博客网 时间:2024/06/07 02:59
早起一水.
求原始序列到有序序列按照规则最少需要移动多少次.
分析下样例
1 2 3 4 5
原始序列: 4 1 5 2 32 4 3 1 5p(p(1))=p(4)=2;
p(p(2))=p(1)=4;
p(p(3))=p(5)=3;
...
...
1 2 5 4 3
p(p(p(1)))=p(2)=1;
p(p(p(2)))=p(4)=2;
p(p(p(3)))=p(3)=5;
...
...
4 1 3 2 5
p(p(p(p(1))))=p(1)=4;
p(p(p(p(2))))=p(2)=1;
p(p(p(p(3))))=p(5)=3;
2 4 5 1 3
1 2 3 4 5
就是两个循环节(1,2,4) 和(3,5) 我们只要求出lcm(循环节长度)便是其需要移动的次数http://blog.csdn.net/kksleric/article/details/7793397这篇文章或许可以看看
.
/*Problem ID: poj 2369meaning: 求乱序到有序最少交换次数Analyzing: 置换群*/#include <iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<vector>using namespace std;typedef struct even{int y1,y2,x;}even;#define FOR(i,s,t) for(int i=(s); i<(t); i++)#define LL long long#define BUG puts("here!!!")#define STOP system("pause")#define file_r(x) freopen(x, "r", stdin)#define file_w(x) freopen(x, "w", stdout)#define maxn 1006LL gcd(LL a,LL b) {return a?gcd(b%a,a):b;}int main(){ int N; int A[maxn],vis[maxn]; scanf("%d",&N); FOR(i,0,N){ scanf("%d",&A[i]); A[i]=A[i]-1; } LL res=1,len; memset(vis,0,sizeof(vis)); FOR(i,0,N){ if(!vis[i]){ int j=i; len=0; while(!vis[j]){ len++; vis[j]=1; j=A[j]; } } res=res/gcd(res,len)*len; } printf("%d\n",res); return 0;}
- poj 2369 Permutations(置换群)
- poj 2369 Permutations (置换群)
- POJ 2369 - Permutations 【置换群】
- POJ 2369 Permutations (置换群)
- POJ 2369 Permutations 置换群
- poj 2369 Permutations 【置换群】
- POJ 2369 Permutations (置换群)
- POJ 2369 Permutations 【置换群】
- POJ 2369 Permutations【置换群】
- POJ 2369 Permutations(置换)
- 【POJ 2369】Permutations(置换群)
- 【POJ】2369 - Permutations(置换群)
- poj 2369 Permutations (置换群入门)
- poj 2369 Permutations【简单置换群*详解】
- poj 2369 Permutations(置换)
- [ACM] poj 2369 Permutations (置换群循环节长度)
- poj 2369-Permutations置换及其应用
- poj 2369 Permutations 置换水题
- fseek()用法
- 图论小结(一)包括一些最短路,最小生成树,差分约束,欧拉回路,的经典题和变种题。强连通,双连通,割点割桥的应用。二分匹配,KM,支配集,独立集,还有2-SAT。
- javascript 打造城市选择控件,兼容IE6以及以上,谷歌,Firefox
- 初识MVC模式
- 10个值得深入的Android应用开源项目
- poj 2369 Permutations(置换群)
- Windows不能在本地计算机启动OracleDBConsoleorcl
- struts2学习笔记——马士兵视频版
- 关闭Oracle数据库shutdown选项
- JavaScript基础
- 最近在使用MyEclipse的SVN插件时总是弹出一个大大的对话框,报一个Failed to load JavaHL Library.错误
- 文字向上滚动
- 写给大学生
- win7下,memCache安装过程