POJ 2369 Permutations
傻逼图论。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxv 1050
#define maxn 1050
#define maxe 2050
using namespace std;
int n,p[maxn],nume=,g[maxv],ans[maxn],sum=,cnt=;
bool vis[maxn];
struct edge
{
int v,nxt;
}e[maxe];
void addedge(int u,int v)
{
e[++nume].v=v;
e[nume].nxt=g[u];
g[u]=nume;
}
int gcd(int x,int y)
{
if (x==) return y;
if (y==) return x;
return gcd(y,x%y);
}
int dfs(int x)
{
vis[x]=true;
for (int i=g[x];i;i=e[i].nxt)
{
if (!vis[e[i].v])
return dfs(e[i].v)+;
}
return ;
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
nume=;
cnt=;sum=;
for (int i=;i<=n;i++)
{
scanf("%d",&p[i]);
addedge(i,p[i]);
addedge(p[i],i);
}
for (int i=;i<=n;i++)
{
if (!vis[i])
ans[++cnt]=dfs(i);
}
for (int i=;i<=cnt;i++)
sum=(sum*ans[i])/gcd(sum,ans[i]);
printf("%d\n",sum);
}
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(置换群概念题)
Description We remind that the permutation of some final set is a one-to-one mapping of the set onto ...
- 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就是所有轮换长度的最小公倍数. 把一个置换转换成轮换的方法也 ...
- poj 2369(置换群)
Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3041 Accepted: 1641 Desc ...
- POJ 2369
我们知道,当循环长度为L时,置换群幂次为K ,则结果是GCD(L,K)个积相乘. 于是,我们只需要求出每个循环的长度,求得它们的最小公倍数即为解. #include <iostream> ...
- acm数学(待续)
意图写出http://www.cnblogs.com/kuangbin/archive/2012/08/28/2661066.html这个东西的完善版. 1.置换,置换的运算 poj 2369 Per ...
随机推荐
- 【译】C++工程师需要掌握的10个C++11特性
原文标题:Ten C++11 Features Every C++ Developer Should Use 原文作者:Marius Bancila 原文地址:codeproject 备注:非直译,带 ...
- 充分发挥异步在 ASP.NET 中的强大优势
作者:Brij Bhushan Mishra 最近几年,异步编程受到极大关注,主要是出于两个关键原因:首先,它有助于提供更好的用户体验,因为不会阻塞 UI 线程,避免了处理结束前出现 UI 界面挂起. ...
- Random的用法
import java.util.Random; public class RandomTest { public static void main(String[] args) { Random r ...
- Eclipse下Python的MySQLdb的安装以及相关问题
前提是要安装好Python以及eclipse和MySQL的相应版本.本文Python为2.7,MySQL为5.1Eclipse为3.6.2 下载完MySQLdb以后,直接安装即可.在eclipse中启 ...
- 更改cmd代码页,修正语言显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 rem 英文 chcp 437 rem 日文 chcp 932 rem 简体中文 chcp 936 re ...
- Axis学习的第一天
下载axis的相关工程包: 选中这2个文件下载: 1)axis-bin-1.4.zip 含有axis工程包,将工程包复制到tomcat里的webapps目录下: 2)axis-src-1.4.zip ...
- C#DataGrdviewl加入checkBox全选删除
#region 加入checkBox /// <summary> /// 加入checkBox /// </summary> /// <param name=" ...
- java jms
这篇博文我们主要介绍J2EE中的一个重要规范JMS,因为这个规范在企业中的应用十分的广泛,也比较重要,我们主要介绍JMS的基本概念和它的模式,消息的消费以及JMS编程步骤. 基本概念 JMS是java ...
- mysql+heartbeat+DRBD+LVS集群
- iOS开发--提交github代码
将的SampleTable例子提交到github 具体步骤如下: a. 首先登陆github b. 创建新的reponsitory name, description c. 打开terminal, c ...