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 ...
随机推荐
- linux配置hadoop集群
①安装虚拟机 ②为虚拟机添加共享文件 右击已经安装好的虚拟机 设置—>选项—>共享文件 ③配置映射 sudo nano /etc/network/interfaces 重启网络:sud ...
- git相关知识(github,idea等的配置)
本地git提交文件到github上: 1.在github上创建项目 2.使用git clone https://github.com/xxxxxxx/xxxxx.git克隆到本地 3.编辑项目 4.g ...
- 创建型模式篇(单例模式Single Pattern)
一.单例模式(Singleton Pattern) 单例模式要求一个类只能有一个实例,并且提供了一个全局的访问点. 比如说,中国主席的职位是Singleton,法律规定主席选举,任何时间只能有一个主席 ...
- django学习之——创建项目
创建项目让我迷茫了会: 直接cmd 执行django-admin.py startproject pro_name 肯定是不行的 必须cd到 D:\Program Files\Python3.3.5 ...
- maven聚合工程使用如何debug
maven聚合工程在正常情况下,使用debug时会出错,因为没有源码,就不会显示代码和断点行数条. 进行如下操作: 默认情况下source下只有默认的default文件夹,点击remove进行删除(这 ...
- Units about ASM
1.ASM Striping and Mirroring:ASM supports two levels of striping: fine striping and coarse striping. ...
- Django之权限管理插件
一.功能分析: 一个成熟的web应用,对权限的控制.管理是不可少的:对于一个web应用来说是什么权限? 这要从web应用的使用说起,用户在浏览器输入一个url,访问server端,server端返回这 ...
- UNIX发展史简介
1965年贝尔实验室(Bell Labs).通用电气(General Electric)和麻省理工学院(MIT)欲共同打造MULTICS(Multiplexed Information and Com ...
- linux network
Linux 1◆ 提供连接 2◆ connection baidu.com 3◆ vm tools install Reboot
- 学习笔记-AngularJs(三)
学习笔记-AngularJs(二)写了个所有程序语言入门时都必须要写的Hello World,那么从现在开始做那个之前说过的互联网大佬介绍的学习例子,当然这里开始会慢慢按照之前说过的目录来搭建这个学习 ...