POJ 2369-Permutations(置换群-K次置换后还原有序)
2017-04-18 20:06
369 查看
Permutations
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
Sample Output
Source
Ural State University Internal Contest October'2000 Junior Session
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3158 | Accepted: 1709 |
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个递增有序元素1~N,多少次置换群的运算能够还原成1~N。解题思路:
据说……置换群中有一个定理:设T为一置换,e为单位置换,T^k=e,那么k的最小正整数解是T的拆分的所有循环长度的最小公倍数。#include<iostream> #include<cstdio> #include<iomanip> #include<cmath> #include<cstdlib> #include<cstring> #include<map> #include<algorithm> #include<vector> #include<queue> using namespace std; #define INF 0xfffffff #define MAXN 1010 long long a[MAXN]; long long gcd(long long a,long long b) { return (a%b!=0?(gcd(b,a%b)):b); } long long lcm(long long u,long long v)//最小公倍数 { long long h; h=gcd(u,v); return(u*v/h); } int main() { #ifdef ONLINE_JUDGE #else freopen("G:/cbx/read.txt","r",stdin); //freopen("G:/cbx/out.txt","w",stdout); #endif int n; scanf("%d",&n); for(int i=0; i<n; ++i) { scanf("%I64d",&a[i]); --a[i]; } int res=1; long long ans=1; for(int i=0; i<n; ++i) { int temp=a[i]; while(1)//求循环节长度 { if(i==temp) { ans=lcm(ans,res);//计算所有循环节的最小公倍数 res=1; break; } ++res; temp=a[temp]; } } printf("%I64d\n",ans); return 0; }
相关文章推荐
- POJ2369 Permutations 置换群循环节
- POJ 2369 Permutations(置换)
- POJ 1026-Cipher(置换群-K次置换 取模循环节长度)
- POJ2369————Permutations(置换群,数论)
- POJ 2369|URAL 1024|Permutations|置换求循环节长度
- POJ 2369 Permutations(置换群概念题)
- [ACM] poj 2369 Permutations (置换群循环节长度)
- [ACM] poj 2369 Permutations (置换群循环节长度)
- poj 2369 Permutations(置换群)
- poj 2369 Permutations(置换)
- POJ2369 Permutations【置换群】
- poj 2369-Permutations置换及其应用
- [ACM] poj 2369 Permutations (置换群循环节长度)
- poj 2369 Permutations (置换群入门)
- POJ 2369 Permutations (置换群)
- POJ 2369 Permutations (置换的秩P^k = I)
- 【置换群】 poj2369 Permutations
- POJ 2369 Permutations (置换群)
- POJ 2369 Permutations (置换的秩P^k = I)
- poj 2369 Permutations 置换水题