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 ...
随机推荐
- Simulate a seven-sided die using only five-sided
问题描述: 如题 转述一下问题,就是说你现在有一个正五面体骰子,然后你怎么用这个正五面体骰子去模拟一个正七面体骰子. 这个问题我接触到几种方法,下面一一阐述. 方法一: rand7()=( rand5 ...
- laravel笔记
向视图中传递变量 使用with()方法 return view('articles.lists')->with('title',$title); 直接给view()传参数 return view ...
- QAQ OI生涯の最后一个月
QAQ 总觉得自己要做点什么 可是并不知道去做些什么 QAQ 先挖一些坑吧,不管怎么样,把这些坑填完估计NOI也就无憾了 1.读完13-16的论文 QAQ 2.做完12-16的POI QAQ 3.做 ...
- converntion
One convention that we have is to use the names of fruits and vegetables for variables(only in small ...
- iOS js oc相互调用(JavaScriptCore)(二)
下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用方法 首先我们看第一种,直接调用方法. 其中用到了iOS的block 上代码 -(void)we ...
- 浅析ODS与EDW关系(转载)
浅析ODS与EDW 关系 刘智琼 (中国电信集团广州研究院广州510630) 摘要 本文重点介绍了企业运营数据仓储(ODS)和企业数据仓库(EDW )的概念,并对ODS与EDW 之间的关系,包括两者相 ...
- android程序获取WIFI的IP地址和MAC地址
转自:http://my.oschina.net/chenj/blog/68680 近日在鼓捣这玩意,拿出来大家分享一下,代码比较简单,如果有不懂的再问 <Button android:id=& ...
- mysql 转义字符和php addslashes
遇到一个很奇怪的问题,json数据中含有中文: "mail":{"title":"\u6218\u529b\u8fbe\u4eba\u6d3b\u52 ...
- 30 个 PHP 的 Excel 处理类
下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1. Read Excel Spreadsheets u ...
- SQL经典问题 找出连续日期及连续的天数
转自:http://bbs.csdn.net/topics/360019248 如何取到每段连续日期的起始终止日期以及持续天数及起始日期距上一期终止日期的天数,能否用一句sql实现?备注:数据库环境是 ...