poj2369

Permutations










Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2549   Accepted: 1336

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

置换群,求置换周期

+ ?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

#include<iostream>

#include<stdio.h>

using
namespace std;

int a[10010];

int lcm(int
x,int y)

{

    if(x==y)

        return
x;

    if(x<y)

        swap(x,y);

    int
i = 2, ans = x;

    while(ans % y != 0)

        ans = x * (i++);

    return
ans;

}

int
main()

{

    int
n,j,i,ans,tmp,num;

    while(scanf("%d",&n)!=EOF)

    {

        ans=1;

        for(i=1; i<=n; i++)

            scanf("%d",&a[i]);

        for(i=1; i<=n; i++)

        {

            tmp = a[i];

            num = 1;

            while(tmp != i)

            {

                tmp = a[tmp];

                num++;

            }

            ans =lcm(ans, num);

        }

        printf("%d\n",ans);

    }

    return
0;

}

  



时间: 2024-08-05 19:35:42

poj2369的相关文章

POJ2369 Permutations【置换群】

题目链接: http://poj.org/problem?id=2369 题目大意: 给定一个序列.问最少须要多少次置换才干变为 1.2.-.N 的有序序列.比方说给 定5个数的序列 4 1 5 2 3.表示置换为: ( 1 2 3 4 5 ) ,即 (1 4 2)(3 5) 4 1 5 2 3 解题思路: 对于每一位找到自己轮换内轮换到自己的次数.求不相交的轮换之间的次数的公倍数, 即为终于结果. AC代码: #include<iostream> #include<algorithm&

置换群学习笔记

群论是数学分支之一,在OI中的运用主要在于置换群和Burnside引理,polya定理. http://blog.csdn.net/liangzhaoyang1/article/details/72639208 http://blog.csdn.net/gengmingrui/article/details/50564027 http://www.cnblogs.com/candy99/category/955780.html https://files.cnblogs.com/files/Ho