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. SQL联合查询中的关键语法

    http://www.cnblogs.com/aaapeng/archive/2010/01/20/1652151.html 联合查询效率较高.以下例子来说明联合查询的好处 t1表结构(用户名,密码) ...

  2. PCA主成分分析 R语言

    1. PCA优缺点 利用PCA达到降维目的,避免高维灾难. PCA把所有样本当作一个整体处理,忽略了类别属性,所以其丢掉的某些属性可能正好包含了重要的分类信息 2. PCA原理 条件1:给定一个m*n ...

  3. 300. Longest Increasing Subsequence_算法有误

    300. Longest Increasing Subsequence 300. Longest Increasing Subsequence Given an unsorted array of i ...

  4. 计数排序与桶排序(bucket sort)

    Bucket Sort is a sorting method that subdivides the given data into various buckets depending on cer ...

  5. Qt error ------ incomplete type 'QApplication' used in nested name specifier

    没有包含 ‘QApplication’ 头文件

  6. 一篇很棒的 MySQL 触发器学习教程

    一.触发器概念 触发器(trigger):监视某种情况,并触发某种操作,它是提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是手工启动 ...

  7. Java并发编程原理与实战四十:JDK8新增LongAdder详解

    传统的原子锁AtomicLong/AtomicInt虽然也可以处理大量并发情况下的计数器,但是由于使用了自旋等待,当存在大量竞争时,会存在大量自旋等待,而导致CPU浪费,而有效计算很少,降低了计算效率 ...

  8. jQuery中的text(),html(),val()的区别

    一.jquery中HTML 1. 无参html() 方法用来获取任意元素的HTML内容,如果你调用多个选定元素的.html()方法,那么其读取的只是第一个元素,换句话说:如果选择器匹配多于一个的元素, ...

  9. WPF控件收集

    1.Extended WPF Toolkit 2.Fluent Ribbon Control Suite 3.WPF Ribbon Control 4.Telerik RadControls for ...

  10. 博主退役了qwq

    noip靠太差的(蒟蒻)博主退役了qwq 感觉以后都没什么机会可以继续写博客了 这个博客八成是坟了呀qwq 其实感觉也没有什么人关注qwq 所以也不长篇大论些什么了 就这样吧qwq