标签:des blog class code c color
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 2549 | Accepted: 1336 |
Description
Input
Output
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; } |
标签:des blog class code c color
原文地址:http://www.cnblogs.com/lxm940130740/p/3720324.html