POJ 2369 Permutations (置换群)
来源:互联网 发布:有没有听音识谱软件 编辑:程序博客网 时间:2024/06/09 23:45
Permutations
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3173 Accepted: 1724
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."
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
54 1 5 2 3
Sample Output
6
题意:按照题目所给的规律交换,问交换多少次可以让数列有序。
思路:置换群,求每个位置的周期,最后求最小公倍数。
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int cir[1005];int key[1005];int n;int main(){ while(cin>>n) { for(int i=1;i<=n;i++) scanf("%d",&key[i]); for(int i=1;i<=n;i++) { int now=key[key[i]]; cir[i]=1; while(now!=key[i]) { now=key[now]; cir[i]++; } } int lcm=1; for(int i=1;i<=n;i++) { lcm=lcm/__gcd(cir[i],lcm)*cir[i]; } cout<<lcm<<endl; } return 0;}
阅读全文
0 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 置换水题
- python 3.4.3 下载安装与环境配置
- json中含有特殊字符串如何处理
- 承载网络
- H5+GeoLocation获取地理位置
- 个人ubuntu安装后的操作安装顺序
- POJ 2369 Permutations (置换群)
- PHP 安装
- Spring mvc-异常javax.servlet.ServletException: Could not resolve view with name 'xxx' in servlet with
- POJ 1008 Maya Calendar (模拟)
- Android开发从0到1024基础篇(3)DataBinding
- git pull总是要输入账号和密码
- serialVersionUID
- .sh数据输出及备份过程
- 通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect的问题