poj2369 Permutations ——置换群
link:http://poj.org/problem?id=2369
置换群,最简单的那种。
找所有数字循环节的最小公倍数。
/*
ID: zypz4571
LANG: C++
TASK: permutations.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
];
];
int gcd(int x, int y) {
? x : gcd(y, x%y);
}
int lcm(int x, int y) {
return x/gcd(x,y)*y;
}
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
int n;
while (~scanf("%d", &n)) {
; i < n; ++i) scanf();
;
memset(flag, false, sizeof(flag));
; i <= n; ++i) {
, pos = i;
if (!flag[pos]) {
for (; !flag[a[pos]]; ++sum) {
flag[a[pos]] = true;
pos = a[pos];
}
ans = lcm(ans, sum);
}
}
printf("%d\n", ans);
}
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
开始有一点不理解,仔细想一想就明白了。把上面的程序模拟一下这个样例:
| 1 | 2 | 3 | 4 | 5 |
| 4 | 1 | 5 | 2 | 3 |
| 2 | 4 | 1 | ||
| 1 | 2 | 4 |
比如,我在对1找循环节的时候,过程中出现了4,那么将来,就不用对4找循环节了。
这么想:1 经过4到达1,那么4一定可以经过1到达4.并且4的循环节必然和1相等!
因为在对1找循环节的时候,你遇到了4,那么这就相当于在这个时候对4找循环节么。很神奇的样子。
多多模拟一下,严格的证明貌似还要好好看一下近世代数。
嗨,中村
poj2369 Permutations ——置换群的更多相关文章
- POJ2369 Permutations【置换群】
题目链接: http://poj.org/problem?id=2369 题目大意: 给定一个序列.问最少须要多少次置换才干变为 1.2.-.N 的有序序列.比方说给 定5个数的序列 4 1 5 2 ...
- POJ2369 Permutations(置换的周期)
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- POJ 2369 Permutations(置换群概念题)
Description We remind that the permutation of some final set is a one-to-one mapping of the set onto ...
- Uva 11077 Find the Permutations [置换群 DP]
题意: 给定$n$和$k$,问有多少排列交换$k$次能变成升序 $n \le 21$ $uva$貌似挂掉了$vjudge$上一直排队 从某个排列到$1,2,...,n$和从$1,2,...,n$到某个 ...
- POJ置换群入门[3/3]
POJ 3270 Cow Sorting 题意: 一个序列变为升序,操作为交换两个元素,代价为两元素之和,求最小代价 题解: 看了黑书... 首先循环因子分解 一个循环完成的最小代价要么是循环中最小元 ...
- acm数学(待续)
意图写出http://www.cnblogs.com/kuangbin/archive/2012/08/28/2661066.html这个东西的完善版. 1.置换,置换的运算 poj 2369 Per ...
- poj1026 Cipher ——置换群
link:http://poj.org/problem?id=1026 其实这道题目和poj2369这道题目一样. 都是基础的置换群题目.把那道题目理解了,这道题就没问题了. 不过我的方法貌似比较挫, ...
- poj 2369(置换群)
Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3041 Accepted: 1641 Desc ...
- Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
随机推荐
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- suds调用webservice
一.安装 pip install suds 二.日志 import logging logging.basicConfig(level=logging.INFO) logging.getLogger( ...
- jQuery的环境配置
目前最新的版本,是 1.10.1 和 2.0.2,如果你需要引用到你线上的项目,就必须使用压缩版,去掉了注释和空白,是容量最小. 从CDN中载入JQuery,如Google中载入JQuery: htt ...
- .net 连接数据库
"@"符号是防止将后面字符串中的"\"解析为转义字符. using System.Data; using System.Data.SqlClient; ... ...
- swig之于c++
[namespace] namespace nsTest1 { int nsAdd(int a, int b) { return a + b; } } namespace nsTest2 { int ...
- SPSS数据分析—分段回归
在SPSS非线性回归过程中,我们讲到了损失函数按钮可以自定义损失函数,但是还有一个约束按钮没有讲到,该按钮的功能是对自 定义的损失函数的参数设定条件,这些条件通常是由逻辑表达式组成,这就使得损失函数具 ...
- C#高级进阶--重写函数
这里要说一下,重写是继承时发生,在子类中重新定义父类中的方法.例如:基类方法声明为virtual方法,派生类中使用override声明此方法的重写. 基类中的访问修饰符在子类中是不能被修改的.比如说基 ...
- roscpp
不服气不行,写ROS这伙就是比我知道的库函数多 inti函数:初始化节点是简单读些命令行参数和环境配置来配置节点名呀,命名空间呀和命名重映射之类东西. 其是在roscpp里面解释很清楚了,只是,我当时 ...
- Objective-C( Category 分类,非正式协议,分类延展)
分类: 主要是给原来类增加一些方法;不可以增加成员变量 Person (Person+eat) 非正式协议: 非正式协议就是类别,即凡是NSObject或其子类Foundation框架中的类增加的类别 ...