Permutations
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3041   Accepted: 1641

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

题意:给出一个集合 p,每次按照一个规则去换掉其中的元素,问使 p^k = p 成立的最小的 k 是多少?

题解:我们将该集合的所有置换群求出来,那么最小的k就是这些群的循环的最小公倍数,比如:
1 2 3 4 5
4 1 5 2 3
上面可以划分出两个群 (1,4,2),(3,5)这两个群的循环分别是 3 ,2 所以最小的 k 就是 3*2 = 6
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL;
const int N = ;
int n;
struct Node{
int val,id;
}node[N];
bool vis[N];
int cmp(Node a,Node b){
return a.val < b.val;
}
int gcd(int a,int b){
return b==?a:gcd(b,a%b);
}
int main()
{
while(scanf("%d",&n)!=EOF){
memset(vis,false,sizeof(vis));
for(int i=;i<=n;i++){
scanf("%d",&node[i].val);
node[i].id = i;
}
sort(node+,node++n,cmp);
int lcm = ;
for(int i=;i<=n;i++){
int loop = ;
int t = i;
while(!vis[t]){
loop++;
vis[t] = true;
t = node[t].id;
}
if(loop){
lcm = lcm/gcd(lcm,loop)*loop;
}
}
printf("%d\n",lcm);
}
return ;
}

poj 2369(置换群)的更多相关文章

  1. POJ 2369 Permutations(置换群概念题)

    Description We remind that the permutation of some final set is a one-to-one mapping of the set onto ...

  2. poj 2369 Permutations - 数论

    We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Les ...

  3. poj 1026(置换群)

    题意:给你一个变换规则,和一个字符串,问经过k次变换后得到的字符串. 思路:开始的时候试图去找它的整个周期,谁知道周期太大了,各种RE,后来在得知此题需要用置换群来优化,第一次接触置换群学习了下! 代 ...

  4. poj 3270(置换群+贪心)

    Cow Sorting Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6993   Accepted: 2754 Descr ...

  5. POJ 3270 置换群问题

    题目大意是: 每头牛都有一个对应的值a[i],现在给定一个初始的牛的序列,希望通过两两交换,能够使这些牛按值升序排列,每次交换都会耗费一个 a[i]+a[j] 希望耗费最小,求出这个最小耗费 个人觉得 ...

  6. POJ 1026 置换群的k次幂问题

    题目大意: 给定了一组对应关系,经过k次幂后,得到新的对应关系b[i],然后将给定的字符串上的第i位字符放置到b[i]的位置上, 如果字符串长度不足n就用空格补足,这里的是空格,也就是str[i] = ...

  7. POJ 2369

    我们知道,当循环长度为L时,置换群幂次为K ,则结果是GCD(L,K)个积相乘. 于是,我们只需要求出每个循环的长度,求得它们的最小公倍数即为解. #include <iostream> ...

  8. POJ 2369 Permutations

    傻逼图论. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  9. poj 3270(置换群)

    题意:给定n头母牛的脾气大小,然后让你通过交换任意两头母牛的位置使得最后的母牛序列的脾气值从小到大,交换两头母牛的代价是两个脾气之和,使得代价最小. 分析:以前做过一道题,只有一个地方和这道题不同,但 ...

随机推荐

  1. 2018 ACM-ICPC 中国大学生程序设计竞赛暨丝绸之路程序设计竞赛

    三道大水题,其它题都不会做,真是尴尬和无奈啊…… 有想法,但是解决不了,感觉个人不会一些基本解法,终究还是个人学习的内容太少了 B. Goldbach /* 数值较小,<2^63,分解的两个素数 ...

  2. 团体程序设计天梯赛 L3-012. 水果忍者

    /*对于一条满足条件的直线,向下移,直到触碰一条线段的下端点,仍然经过其它线段,该直线仍然满足条件 即以一条线段的下(上)端点作为直线上的一点,求为了经过一条线段的最小.最大斜率值(mink,maxk ...

  3. 团体程序设计天梯赛 L3-016. 二叉搜索树的结构

    #include <cstdio> #include <cstdlib> #include <string.h> #include <math.h> # ...

  4. Linux下的wine生活(QQ/微信/Office)

    My wine life like windows 本篇内容涉及QQ.微信.Office在wine中的使用配置. QQ 到deepin下载轻聊版. 如果安装了crossover,那么将其中opt/cx ...

  5. 利用VisualStudio单元测试框架举一个简单的单元测试例子

    本随笔很简单,不涉及mock和stub对象,而是只给出一个简单的利用Visual Studio单元测试框架的最简单例子.如果需要深入理解Unit Test的原理与艺术,请参考<The art o ...

  6. 科学计算三维可视化---Traits属性的功能

    Traits属性的功能 Traits库为python的属性增加了类型定义的功能,除此之外他还提供了5个特殊的功能(可以为用户的界面响应提供基本能力):初始化:每个traits属性都有自己的默认值验证: ...

  7. call 大佬 三分姿势

    为什么注释掉的三分方式不能过 @大佬 题目来源:http://hihocoder.com/problemset/problem/1142?sid=1003381 貌似不是eps的问题 #include ...

  8. 华为mate 10 pro安装失败,提示没有未包含任何证书

    原因: Android 7.0 引入一项新的应用签名方案 APK Signature Scheme v2,它能提供更快的应用安装时间和更多针对未授权 APK 文件更改的保护.在默认情况下,Androi ...

  9. 推荐一款超级漂亮的HTML5 CSS3的图片轮播器

    最近在学习HTML5和CSS3,印象最深的是CSS3的动画功能,不仅有浏览器原生支持,执行效率高,而且免去在js中自己管理timer. 本来想写一个图片轮播器练练手,结果在网上发现一个国人写的开源的图 ...

  10. 倍增 Tarjan 求LCA

                                                                                                         ...