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 ...
随机推荐
- 压测2.0:云压测 + APM = 端到端压测解决方案
从压力测试说起 压力测试是确立系统稳定性的一种测试方法,通常在系统正常运作范围之外进行,以考察其功能极限和隐患.与功能测试不同,压测是以软件响应速度为测试目标的,尤其是针对在较短时间内大量并发用户的访 ...
- Javascript 图片延迟加载之理论基础
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 由CAST()函数在.NET1.1和.NET4.0下处理机制不同所引发的BUG
.NET 1.1版本下使用日期强制转换函数,比如:"select cast(ActionDate as char(7)) as ActionDate from ST_BookAction ...
- Xamarin for Visual Studio 3.11.666 Beta版 破解补丁
注意:本版本是 Beta 版 现已推送到稳定频道 前提概要 全新安装请参考 安装 Xamarin for Visual Studio. 最新稳定版请参考 Xamarin for Visual St ...
- (2)在vs2010上配置opengl
参考自http://www.yakergong.net/nehe/ 在Visual Studio 2003 中创建基于Nehe SDK的应用程序分为以下几个步骤: 创建一个空白的工程文件 包含Nehe ...
- 【hdu2815-Mod Tree】高次同余方程-拓展BadyStepGaintStep
http://acm.hdu.edu.cn/showproblem.php?pid=2815 题意:裸题... 关于拓展BSGS的详细解释我写了一篇博文:http://www.cnblogs.com/ ...
- lintcode :最长公共子串
题目 最长公共子串 给出两个字符串,找到最长公共子串,并返回其长度. 样例 给出A=“ABCD”,B=“CBCE”,返回 2 注意 子串的字符应该连续的出现在原字符串中,这与子序列有所不同. 解题 注 ...
- Android核心分析之二十四Android GDI之显示缓冲管理
Android GDI之屏幕设备管理-动态链接库 万丈高楼从地起,从最根源的硬件帧缓冲区开始.我们知道显示FrameBuffer在系统中就是一段内存,GDI的工作就是把需要输出的内容放入到该段内存的某 ...
- Python3导入自定义模块的3种方式
前话 最近跟着廖雪峰的教程学到 模块 这一节.关于如何自定义一个模块,如果大家不懂的话还请先看下面这篇博文 ↓ http://www.liaoxuefeng.com/wiki/001431608955 ...
- Spring_MVC_教程_快速入门_深入分析
Spring MVC 教程,快速入门,深入分析 博客分类: SPRING Spring MVC 教程快速入门 资源下载: Spring_MVC_教程_快速入门_深入分析V1.1.pdf Spring ...