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 ...
随机推荐
- 解决方法 test: database removal failed: ERROR: database "test" is being accessed by other users
select * from pg_stat_activity where datname='test'; 找出哪个进程用了这个数据库,然后删除这个进程(pid) kill -9 47182 然后再删除 ...
- Java线程中yield与join方法的区别
长期以来,多线程问题颇为受到面试官的青睐.虽然我个人认为我们当中很少有人能真正获得机会开发复杂的多线程应用(在过去的七年中,我得到了一个机会),但是理解多线程对增加你的信心很有用.之前,我讨论了一个w ...
- MFC编程入门之十七(对话框:文件对话框)
上一讲介绍的是消息对话框,本节讲解文件对话框.文件对话框也是很常用的一类对话框. 文件对话框的分类 文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中经常见到这两种文件对话框 ...
- windows下的Nodejs及npm的安装、常用命令,Nodejs开发环境配置
http://www.cnblogs.com/webstorm/p/5744942.html ***************************************** 第一步:下载Nodej ...
- iOS开发之滤镜的使用技巧(CoreImage)
一.滤镜的内容和效果是比较多并且复杂的 ,学习滤镜需要技巧 如下: 两个输出语句解决滤镜的属性选择问题: 1.查询效果分类中包含什么效果按住command 点击CIFilter 进入接口文件 找到第1 ...
- Head First 设计模式 --4 工厂模式 抽象工厂模式
(用到了依赖倒置原则) 我们写的代码中,有的时候可能会出现根据外面给定的不同的参数在方法中根据参数实例化不同的实例,就是会根据不同的参数会new出不同的实例.如果这么写了,这段代码会非常的脆弱,一旦出 ...
- 浅谈HTTP协议(下)
下面来讲响应消息.响应消息也分为响应起始行.响应头部.CRLF.响应主体. 响应起始行包括协议版本.响应状态码.原因短句.这里的重点就是响应状态码,它一共分为5类,状态码准确的说是一个三位数. 1xx ...
- 【转】Image Cyborg 一键下载存储网页所有图片
下午仿照网上例子写了个抓取网页中图片并保存到本地的Python的例子,好奇就google了下是否有类似的在线抓取图片的外挂工具. 接着就找到了Pseric写的这篇文章 - Image Cyborg 一 ...
- 6/8/9/10/11 Sprint2 看板和燃尽图
端午放假,大家都回家了 页面模块的大体设计,因所找的资料不全,还待改善
- IOS 核心动画之CAKeyframeAnimation - iBaby
- IOS 核心动画之CAKeyframeAnimation - 简单介绍 是CApropertyAnimation的子类,跟CABasicAnimation的区别是:CABasicAnimation ...