POJ 2369|URAL 1024|Permutations|置换求循环节长度
来源:互联网 发布:数据库查询怎么保存 编辑:程序博客网 时间:2024/06/07 19:55
题目
我们注意到一些不可变集合(?)的置换是一个一对一的自我映射。更通俗地说,置换是重新排序集合的一种方法。举个例子:我们定义
也就是说,我们定义置换P为:
那么
自然,我们定义
置换中有一个很重要的置换:
显然
下面有一个定理:令
输入
输入的第一行一个正整数
接下来一行N个整数
输出
一行一个正整数k,你可以认为
题解
如果
#include <cstdio>#define FOR(i,j,k) for(i=j;i<=k;++i)const int N = 1005;int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b);}int lcm(int a, int b) { return a / gcd(a, b) * b;}int p[N], vis[N];int main() { int n, ans = 1, i; scanf("%d", &n); FOR(i,1,n) scanf("%d", &p[i]); FOR(i,1,n) if (!vis[i]) { int x = 0; for (int j = i; !vis[j]; j = p[j]) { vis[j] = 1; ++x; } ans = lcm(ans, x); } printf("%d\n", ans); return 0;}
阅读全文
0 0
- POJ 2369|URAL 1024|Permutations|置换求循环节长度
- [ACM] poj 2369 Permutations (置换群循环节长度)
- POJ 2369 Permutations(置换)
- poj 2369 Permutations(置换群)
- poj 2369 Permutations (置换群)
- POJ 2369 - Permutations 【置换群】
- POJ 2369 Permutations (置换群)
- POJ 2369 Permutations 置换群
- poj 2369 Permutations 【置换群】
- poj 2369 Permutations(置换)
- POJ 2369 Permutations (置换群)
- POJ 2369 Permutations 【置换群】
- POJ 2369 Permutations【置换群】
- POJ2369 Permutations 置换群循环节
- POJ 1026-Cipher(置换群-K次置换 取模循环节长度)
- poj 2369-Permutations置换及其应用
- poj 2369 Permutations 置换水题
- 【POJ 2369】Permutations(置换群)
- C#--WinForm--实现查询列表的动态排序
- OAF 页面初始化的基本代码形式一览
- ios 网络链接
- 设计模式之抽象工厂模式的简单实现
- 优雅的REST APIs文档管理
- POJ 2369|URAL 1024|Permutations|置换求循环节长度
- win10系统下caffe环境的搭建
- wm_contact合并函数
- python模块学习pandas(-)
- java读取、写入保存、遍历ini文件配置数据
- 中文分词
- Eclipse Debug 测试
- Java之多线程死锁-yellowcong
- bzoj4540: [Hnoi2016]序列