POJ 2369 Permutations【置换群】
来源:互联网 发布:js饼图 编辑:程序博客网 时间:2024/06/07 12:18
Description
We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows:
This record defines a permutation P as follows: P(1) = 4, P(2) = 1, P(3) = 5, etc.
What is the value of the expression P(P(1))? It’s clear, that P(P(1)) = P(4) = 2. And P(P(3)) = P(5) = 3. One can easily see that if P(n) is a permutation then P(P(n)) is a permutation as well. In our example (believe us)
It is natural to denote this permutation by P2(n) = P(P(n)). In a general form the defenition is as follows: P(n) = P1(n), Pk(n) = P(Pk-1(n)). Among the permutations there is a very important one — that moves nothing:
It is clear that for every k the following relation is satisfied: (EN)k = EN. The following less trivial statement is correct (we won’t prove it here, you may prove it yourself incidentally): Let P(n) be some permutation of an N elements set. Then there exists a natural number k, that Pk = EN. The least natural k such that Pk = EN is called an order of the permutation P.
The problem that your program should solve is formulated now in a very simple manner: “Given a permutation find its order.”
Input
In the first line of the standard input an only natural number N (1 <= N <= 1000) is contained, that is a number of elements in the set that is rearranged by this permutation. In the second line there are N natural numbers of the range from 1 up to N, separated by a space, that define a permutation — the numbers P(1), P(2),…, P(N).
Output
You should write an only natural number to the standard output, that is an order of the permutation. You may consider that an answer shouldn’t exceed 109.
Sample Input
5
4 1 5 2 3
Sample Output
6
Source
Ural State University Internal Contest October’2000 Junior Session
题意:给定n个元素的序列a[],一次变换后a[i] = a[a[i]],问经过多少次变换使得序列变回原来的样子。‘
基础置换群,求出所有群的周期,求其最小公倍数’
#include <iostream> #include<cstdio>#include<iomanip>#include<cmath>#define INF 0x3f3f3f3f #define MAXN (1000+10) #define mem(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define LL long long using namespace std;int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}int lcm(int a, int b) { return a / gcd(a, b) * b;}int a[MAXN]; bool vis[MAXN];int main(){ int n; while (scanf("%d",&n) != EOF) { for (int i = 1; i <= n; i++) scanf("%d",&a[i]); int ans = 1; mem(vis, false); for (int i = 1; i <= n; i++) { if (vis[i]) continue; vis[i] = true; int j = a[i]; int cnt = 1; while (i != j) { cnt++; j = a[j]; } ans = lcm(ans, cnt); } printf("%d\n",ans); } 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 置换水题
- QT编译Android项目遇到的问题
- eclipse 安装FindBugs插件
- “模块化设备”的春天即将来临?
- 【滴滴】求N!末尾0的个数
- Android音频开发之AudioTrack实时播放
- POJ 2369 Permutations【置换群】
- Maven项目启动时Classnotfound
- 启动/停止MySQL服务的方法
- 图文演示业务流程图怎么画的绘制技巧
- 「python」比较关系运算符
- java基本类型与包装类型
- 快速排序实现-JAVA
- Html.Partial和Html. RenderPartial用法
- 机器学习 AdaBoost算法的MATLAB实现