ural 1024. Permutations (置换群)
来源:互联网 发布:js table tbody 编辑:程序博客网 时间:2024/06/16 08:41
算法:
对于第i个数,模拟计算出其置换周期,记为ai,答案就是所有ai的最小公倍数。
1 2 3 4 5
4 1 5 2 3
次数:3 3 2 3 2,最小公倍数6.
#include <iostream>#include <cstdio>int gcd(int a, int b){ if (b == 0) return a; else return gcd(b, a % b);}int lcm(int a, int b){ return a / gcd(a, b) * b;}int rota(int *f, int i){ int num = 1; int t = f[i]; while (f[i] != f[t]) { t = f[t]; ++num; } return num;} int main(){ int n; scanf("%d", &n); int f[n+1]; for (int i = 1; i <= n; ++i) { scanf("%d", &f[i]); } int ans = 1; for (int i = 1; i <= n; ++i) { int num = rota(f, i); ans = lcm(ans, num); } printf("%d\n", ans); //system("pause"); return 0;}
- ural 1024. Permutations (置换群)
- Permutations(hdu2369,置换群)
- 【POJ 2369】Permutations(置换群)
- 【POJ】2369 - Permutations(置换群)
- 【置换群】 poj2369 Permutations
- poj2369 Permutations 置换群
- POJ2369 Permutations【置换群】
- ural 1024. Permutations
- URAL 1024. Permutations
- POJ 2369|URAL 1024|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 【置换群】
- elixir 速成
- android 设计模式之桥接模式.
- div 水平垂直居中
- hdu2896(ac自动机)
- C#使用Ms Chart 实现饼图
- ural 1024. Permutations (置换群)
- Wall Time
- Howto Red hat enterprise Linux 5 configure the network card
- GLSL着色器实现高斯滤波代码
- OpenCV中OpenCL模块函数
- Union All/Union/Intersect操作
- 线索二叉树
- ASO技巧详解(3):截图等因素对ASO的影响
- linux内核移植-移植2.6.35.4内核到s3c2440