题意:给你一堆无序的数列p,求k,使得p^k=p

思路:利用置换的性质,先找出所有的循环,然后循环中元素的个数的lcm就是答案

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#define maxn 1234
using namespace std; int gcd(int a,int b)
{
if(b==) return a;
else return gcd(b,a%b);
} int lcm(int a,int b)
{
return a*b/gcd(a,b);
} int main(int argc, char const *argv[])
{
int n;
int data[maxn];
bool visit[maxn];
int ans;
while(cin>>n)
{
for(int i=;i<=n;i++)
cin>>data[i];
ans=;
memset(visit,false,sizeof(visit));
for(int i=;i<=n;i++)
{
if(!visit[i])
{
int len=;
visit[i]=true;
int tmp = data[i];
while(tmp!=i)
{
visit[tmp]=true;
tmp=data[tmp];
len++;
}
ans=lcm(ans,len);
}
}
cout<<ans<<endl;
}
return ;
}

poj 2369 Permutations (置换入门)的更多相关文章

  1. poj 2369 Permutations 置换

    题目链接 给一个数列, 求这个数列置换成1, 2, 3....n需要多少次. 就是里面所有小的置换的长度的lcm. #include <iostream> #include <vec ...

  2. POJ 2369 Permutations (置换的秩P^k = I)

    题意 给定一个置换形式如,问经过几次置换可以变为恒等置换 思路 就是求k使得Pk = I. 我们知道一个置换可以表示为几个轮换的乘积,那么k就是所有轮换长度的最小公倍数. 把一个置换转换成轮换的方法也 ...

  3. poj 2369 Permutations - 数论

    We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Les ...

  4. POJ 2369 Permutations(置换群概念题)

    Description We remind that the permutation of some final set is a one-to-one mapping of the set onto ...

  5. POJ 2369 Permutations

    傻逼图论. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  6. poj 2369 Permutations 更换水称号

    寻找循环节求lcm够了,如果答案是12345应该输出1.这是下一个洞. #include<iostream> #include<cstdio> #include<cstr ...

  7. poj 3270 Cow Sorting (置换入门)

    题意:给你一个无序数列,让你两两交换将其排成一个非递减的序列,每次交换的花费交换的两个数之和,问你最小的花费 思路:首先了解一下什么是置换,置换即定义S = {1,...,n}到其自身的一个双射函数f ...

  8. poj3270 && poj 1026(置换问题)

    | 1 2 3 4 5 6 | | 3 6 5 1 4 2 | 在一个置换下,x1->x2,x2->x3,...,xn->x1, 每一个置换都可以唯一的分解为若干个不交的循环 如上面 ...

  9. 【UVA 11077】 Find the Permutations (置换+第一类斯特林数)

    Find the Permutations Sorting is one of the most used operations in real life, where Computer Scienc ...

随机推荐

  1. PHP基础学习(函数一)

    PHP(Hypertext Preprocessor):超文本预处理器,一种嵌入在HTML中并且运行在服务器端的脚本语言. var_dump--打印变量相关信息 说明:  <?php var_d ...

  2. [编织消息框架][rpc]使用篇

    rpc 分两部份,一个是调用者,另一方是服务提供者 调用者只关心那个服务,传相应参数,返回内容就可以 而提供者根据调用相应服务同参数,工作处理后响应内容即可 根据他们的关系可以用JAVA 接口同实现类 ...

  3. java Log日志规范

    Overview 一个在生产环境里运行的程序如果没有日志是很让维护者提心吊胆的,有太多杂乱又无意义的日志也是令人伤神.程序出现问题时候,从日志里如果发现不了问题可能的原因是很令人受挫的.本文想讨论的是 ...

  4. SpringMVC-HelloWorld (XML)

    Spring2.5.6开启了Spring的注解时代,简化了的xml配置,提高了开发效率:但是,对于Spring的初学者,xml配置更容易理解的Spring的Ioc特性,aop特性:本文使用Maven构 ...

  5. Playground 你不知道的小技巧, CoreData 的使用

    Playground 的出现无疑是大大的提高了开发效率,可以节省大量的编译时间. 这里介绍在 Playground 中使用 CoreData 的小技巧. 我们新建一个工程 iOS 项目工程. 点击Fi ...

  6. tp框架 :操作数据库

    操作数据库,进行增删改数据 一.对数据表添加数据(方法:add()) (1)上一篇已经讲过链接数据库了,继续进行对数据库的操作,还是用控制器文件中的HomeController.class文件 看下数 ...

  7. 阶乘运算——ACM

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  8. 循环单词 java

    链接:https://www.nowcoder.com/questionTerminal/9d5fbe7750a34d0b91c73943f93b2d7d来源:牛客网如果一个单词通过循环右移获得的单词 ...

  9. ANdrod Studio查看Sha1的方法

    在用Studio做开发中,有时候根据业务需求,需要集成一些SDk,举个例子,百度的鹰眼定位,当然还有很多,在创建项目的时候需要输入sha1值,这个sha1值的获取有多种方式,我记得百度有个检测,就可以 ...

  10. Solr DateRangeField

    Solr DateRangeField 是solr5.0 实现的一个feature. 关于 DateRangeField 支持日期查询如  date_field:[2016-03-23 TO 2017 ...