poj 2369(置换群)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 3041 | Accepted: 1641 |
Description

This record defines a permutation P as follows: P(1) = 4, P(2) = 1, P(3) = 5, etc.
What is the value of the expression P(P(1))? It’s clear, that
P(P(1)) = P(4) = 2. And P(P(3)) = P(5) = 3. One can easily see that if
P(n) is a permutation then P(P(n)) is a permutation as well. In our
example (believe us)

It is natural to denote this permutation by P2(n) = P(P(n)). In a
general form the defenition is as follows: P(n) = P1(n), Pk(n) =
P(Pk-1(n)). Among the permutations there is a very important one — that
moves nothing:

It is clear that for every k the following relation is satisfied:
(EN)k = EN. The following less trivial statement is correct (we won't
prove it here, you may prove it yourself incidentally): Let P(n) be some
permutation of an N elements set. Then there exists a natural number k,
that Pk = EN. The least natural k such that Pk = EN is called an order
of the permutation P.
The problem that your program should solve is formulated now in a very simple manner: "Given a permutation find its order."
Input
the first line of the standard input an only natural number N (1 <= N
<= 1000) is contained, that is a number of elements in the set that
is rearranged by this permutation. In the second line there are N
natural numbers of the range from 1 up to N, separated by a space, that
define a permutation — the numbers P(1), P(2),…, P(N).
Output
should write an only natural number to the standard output, that is an
order of the permutation. You may consider that an answer shouldn't
exceed 109.
Sample Input
5
4 1 5 2 3
Sample Output
6 题意:给出一个集合 p,每次按照一个规则去换掉其中的元素,问使 p^k = p 成立的最小的 k 是多少? 题解:我们将该集合的所有置换群求出来,那么最小的k就是这些群的循环的最小公倍数,比如:
1 2 3 4 5
4 1 5 2 3
上面可以划分出两个群 (1,4,2),(3,5)这两个群的循环分别是 3 ,2 所以最小的 k 就是 3*2 = 6
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long LL;
const int N = ;
int n;
struct Node{
int val,id;
}node[N];
bool vis[N];
int cmp(Node a,Node b){
return a.val < b.val;
}
int gcd(int a,int b){
return b==?a:gcd(b,a%b);
}
int main()
{
while(scanf("%d",&n)!=EOF){
memset(vis,false,sizeof(vis));
for(int i=;i<=n;i++){
scanf("%d",&node[i].val);
node[i].id = i;
}
sort(node+,node++n,cmp);
int lcm = ;
for(int i=;i<=n;i++){
int loop = ;
int t = i;
while(!vis[t]){
loop++;
vis[t] = true;
t = node[t].id;
}
if(loop){
lcm = lcm/gcd(lcm,loop)*loop;
}
}
printf("%d\n",lcm);
}
return ;
}
poj 2369(置换群)的更多相关文章
- 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 - 数论
We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Les ...
- poj 1026(置换群)
题意:给你一个变换规则,和一个字符串,问经过k次变换后得到的字符串. 思路:开始的时候试图去找它的整个周期,谁知道周期太大了,各种RE,后来在得知此题需要用置换群来优化,第一次接触置换群学习了下! 代 ...
- poj 3270(置换群+贪心)
Cow Sorting Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6993 Accepted: 2754 Descr ...
- POJ 3270 置换群问题
题目大意是: 每头牛都有一个对应的值a[i],现在给定一个初始的牛的序列,希望通过两两交换,能够使这些牛按值升序排列,每次交换都会耗费一个 a[i]+a[j] 希望耗费最小,求出这个最小耗费 个人觉得 ...
- POJ 1026 置换群的k次幂问题
题目大意: 给定了一组对应关系,经过k次幂后,得到新的对应关系b[i],然后将给定的字符串上的第i位字符放置到b[i]的位置上, 如果字符串长度不足n就用空格补足,这里的是空格,也就是str[i] = ...
- POJ 2369
我们知道,当循环长度为L时,置换群幂次为K ,则结果是GCD(L,K)个积相乘. 于是,我们只需要求出每个循环的长度,求得它们的最小公倍数即为解. #include <iostream> ...
- POJ 2369 Permutations
傻逼图论. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...
- poj 3270(置换群)
题意:给定n头母牛的脾气大小,然后让你通过交换任意两头母牛的位置使得最后的母牛序列的脾气值从小到大,交换两头母牛的代价是两个脾气之和,使得代价最小. 分析:以前做过一道题,只有一个地方和这道题不同,但 ...
随机推荐
- SpringMVC 上传文件(文件非必填)MultipartHttpServletRequest
原文:https://blog.csdn.net/dorothy1224/article/details/79136676 上传文件(文件非必填)MultipartHttpServletRequest ...
- node中异步IO的理解
解释性语言和编译型语言的区别: 计算器不能直接的理解高级语言,只能理解机器语言,所以必须把高级语言翻译为机器语言,翻译的方式有两种,一个是编译,一个是解释. 解释性语言的程序不需要编译,它是在运行程序 ...
- np.repeat函数
np.repeat用法 觉得有用的话,欢迎一起讨论相互学习~Follow Me np.repeat用于将numpy数组重复 一维数组重复三次 import numpy as np # 随机生成[0,5 ...
- 转:iOS-CoreLocation:无论你在哪里,我都要找到你!
1.定位 使用步骤: 创建CLLocationManager示例,并且需要强引用它 设置CLLocationManager的代理,监听并获取所更新的位置 启动位置更新 1 2 3 _manager = ...
- C++持有Object-C对象时容易内存泄露
在IOS项目中,可以将C++与Object-C混编,不过必须放在实现文件.mm中. 在.mm中,我们可能创建了一个C++对象A,而它持有一个Object-C对象B作为成员变量.当A对象被释放掉的时候, ...
- 科学计算三维可视化---Mayavi入门(Mayavi管线)
一:Mayavi管线 mlab.show_pipeline() #显示管线层级,来打开管线对话框 (一)管线中的对象scene Mayavi Scene:处于树的最顶层的对象,他表示场景,配置界面中可 ...
- JS中浮点数精度误差解决
问题出现 0.1 + 0.2 = 0.30000000000000004 问题分析 对于浮点数的四则运算,几乎所有的编程语言都会有类似精度误差的问题,只不过在 C++/C#/Java 这些语言中已经封 ...
- Jenkins配置定时任务
在任务配置中,滚动到构建触发器-->勾选"Build periodically"-->在输入框中配置触发时间 以上配置,表示在6月13日23点触发. 如果配置成 00 ...
- VBS 重启 TP-Link 路由器
分享一个自己用的小工具,重启TP-Link路由器的,好像还是大学时候写的,献丑了. 其他路由器可能有些不同,但是思路都是差不多的. user = "admin" '路由器帐号 pa ...
- nginx 跨域配置
server { listen 80; server_name b.com; location /{ if ( $http_referer ~* (a.com|b.com|c.com) ) { Acc ...