题意:给你一堆无序的数列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. CentOS7.0安装Nginx

    安装Nginx yum install nginx 正常情况下必定是: 已加载插件:fastestmirror, langpacks base | :: docker-main | :: extras ...

  2. Windows下安装Redis数据库并实现C#访问

    1.Redis在Windows下的安装 目前Redis官方并不支持Redis的Windows版本,需要去GitHub下载. GitHub上的Redis分两种,一种是以命令行形式安装的,一种是以Wind ...

  3. PHP链接Redis

    命令行下运行 redis-server.exe redis.windows.conf 此时,redis服务已经开启,然后我们可以再新开一个命令行,作为控制台 redis-cli.exe -h 127. ...

  4. 原生js中slice()方法和splice()区别

    slice()方法和splice()方法都是原生js中对数组操作的方法. slice(),返回一个新的数组,该方法可从已有的数组中返回选定的元素.例如:arrObject(start,end),sta ...

  5. Vue学习之路---No.1(分享心得,欢迎批评指正)

    首先为了打消大家对Vue.js存在的顾虑,先通过大家所熟知的JQ作为对比. 都知道JQ的语法相对简单.清楚.使用方便.功能齐全: 那么Vue.js呢,同样的,Vue.js与JQ在很多地方都是相同之处, ...

  6. C语言学习心得

    最近学习了C语言,打脑壳,很多东西不会用,没有概念,单点知识都懂,组合起来就不知道怎么弄了.慢慢来吧

  7. li点击弹出序号

    <body> <ul> <li>test1</li> <li>test2</li> <li>test3</li ...

  8. Matlab自带常用的分类器,直接复制用就好了,很方面。

    很方面的,懒得自己写了. clc   clear all     load('wdtFeature');         %   训练样本:train_data             % 矩阵,每行 ...

  9. Remove Element leetcode

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  10. win10环境下jdk1.8+Android Developer Tools Build: v22.3.0-887826的问题

    最进换了新电脑,配置开发环境,最新的android studio 要求jdk1.8,所以想都没想就下载1.8. 之后为了一个原来的老项目,得使用adt,遂装之,遇到一下问题 1.ADT新建项目src下 ...