POJ 2369 Permutations(置换群概念题)
Description

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
Output
Sample Input
5
4 1 5 2 3
Sample Output
6 启发博客:http://blog.csdn.net/tc_to_top/article/details/48132609 题目大意:求将一个排列p(n)还原成En(1,2,3,4...)的最小置换次数 题目分析:计算置换中每个循环节内元素的个数,答案就是这个数的最小公倍数,很好理解,假设某个循环节包含3个元素,则这个循环节还原需要3次,另一个循环节包含2个元素,需要2次置换还原,因此我要让全部序列都还原,只需要取它们的最小公倍数即可
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string.h>
using namespace std; int a[];
bool vis[];
long long gcd(long long b,long long c)//计算最大公约数
{
return c==?b:gcd(c,b%c);
} long long lcm(long long b,long long c)//计算最小公倍数
{
return b * c/ gcd(b, c);
} int main()
{
int n,i,tmp,j;
long long res;
while(~scanf("%d",&n))
{
for(i=;i<=n;i++)
scanf("%d",&a[i]);
memset(vis,false,sizeof(vis));
res=;
for(i=;i<=n;i++)
{
if(!vis[i])
{
j=i;
tmp=;
while(!vis[j])
{
vis[j]=true;
tmp++;
j=a[j];
}
}
res=lcm(res,(long long)tmp);
}
printf("%lld\n",res);
}
return ;
}
POJ 2369 Permutations(置换群概念题)的更多相关文章
- poj 2369 Permutations - 数论
We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Les ...
- POJ 2369 Permutations
傻逼图论. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...
- poj 2369 Permutations 置换
题目链接 给一个数列, 求这个数列置换成1, 2, 3....n需要多少次. 就是里面所有小的置换的长度的lcm. #include <iostream> #include <vec ...
- poj 2369 Permutations 更换水称号
寻找循环节求lcm够了,如果答案是12345应该输出1.这是下一个洞. #include<iostream> #include<cstdio> #include<cstr ...
- poj 2369 Permutations (置换入门)
题意:给你一堆无序的数列p,求k,使得p^k=p 思路:利用置换的性质,先找出所有的循环,然后循环中元素的个数的lcm就是答案 代码: #include <cstdio> #include ...
- POJ 2369 Permutations (置换的秩P^k = I)
题意 给定一个置换形式如,问经过几次置换可以变为恒等置换 思路 就是求k使得Pk = I. 我们知道一个置换可以表示为几个轮换的乘积,那么k就是所有轮换长度的最小公倍数. 把一个置换转换成轮换的方法也 ...
- Sliding Window POJ - 2823 单调队列模板题
Sliding Window POJ - 2823 单调队列模板题 题意 给出一个数列 并且给出一个数m 问每个连续的m中的最小\最大值是多少,并输出 思路 使用单调队列来写,拿最小值来举例 要求区间 ...
- POJ 1488 Tex Quotes --- 水题
POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...
- poj 2369(置换群)
Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3041 Accepted: 1641 Desc ...
随机推荐
- 根据科目计算父科目ID,并递归累计求父科目的金额
通常情况下,我们会从外部系统或者其他数据源得到以下树形结构的数据,并需要对其进行处理 其中,需要做的处理包括 1.计算每个科目的父科目ID,即PARENT_ID; 2.计算每个科目的ITEM_LEVE ...
- 基本数据类型int,bool,str
.基本数据类型(int,bool,str) 基本数据数据类型: int 整数 str 字符串. 一般不存放大量的数据 bool 布尔值. 用来判断. True, False list 列表.用来存放大 ...
- android project
- Linux tar压缩命令 排除某个目录 (根据man tar 总结)
一般直接用tar命令打包很简单,直接使用 tar -zcvf test.tar.gz test 即可. 在很多时候,我们要对某一个目录打包,而这个目录下有几十个子目录和子文件,我们需要在打包的时候排除 ...
- Qt_阴影效果
一.控件阴影效果 为子部件添加阴影比较简单,使用如下方式: QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffe ...
- selinux介绍/状态查看/开启/关闭
SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统--百度百科. 基于经验来说SELinux在 ...
- 微信小程序 HMACSHA256 哈希加密
下载CryptoJS, 增加红色的这句 module.exports = CryptoJS /* CryptoJS code.google.com/p/crypto-js (c) 2009-2012 ...
- centos6.5 安装PHP7.0支持nginx
1.安装PHP所需要的扩展 yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel ...
- Linux的安装包命令/yum 与 Rpm
1.Rpm安装包命令(以dhcp软件包为例)----Rpm安装软件包需要解决依赖性,因此特别麻烦(如图2被需要). rpm与yum安装的均为二进制软件包.类似于windows下载的软件包,可直接安装使 ...
- UVa 11384 - Help is needed for Dexter 分析, 树状数组 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...