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 5842 Lweb and String(Lweb与字符串)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- Linux架构
Linux架构 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我以下图为基础,说明Linux的架构(architecture ...
- BZOJ 2286: [Sdoi2011]消耗战
2286: [Sdoi2011消耗战 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 2082 Solved: 736[Submit][Status] ...
- [luogu2982][USACO10FEB]慢下来Slowing down(树状数组+dfs序)
题目描述 Every day each of Farmer John's N (1 <= N <= 100,000) cows conveniently numbered 1..N mov ...
- Java通过jedis操作redis缓存
package com.wodexiangce.util; import java.util.Set; import redis.clients.jedis.Jedis; /** * redis工具类 ...
- c++ *.h和*.cpp在编译中的作用
首先,我们可以将所有东西都放在一个.cpp文件内.然后编译器就将这个.cpp编译成.obj,obj是什么东西?就是编译单元了. 一个程序,可以由一个编译单元组成,也可以有多个编译单元组成. 如果你不想 ...
- IAR更改代码字体&快速模板设置。——Arvin
1.是用软件提供的字体 如果只想简单的设置,可进行如下设置Tools->IDE Options->Editor->Colors and Fonts->Editor Font-& ...
- Red Hat 6.0 Linux系统跳过登录界面直接进入系统
修改/etc/init/tty.conf文件将exec /sbin/mingetty $TTY改为exec /sbin/mingetty --autologin root $TTY 或者修改/etc/ ...
- 了解Sql Server的执行计划
前一篇总结了Sql Server Profiler,它主要用来监控数据库,并跟踪生成的sql语句.但是只拿到生成的sql语句没有什么用,我们可以利用这些sql语句,然后结合执行计划来分析sql语句的性 ...
- Html=>Head=>meta
如今智能机遍布大街小巷,所以,如今的前端攻城师们要大 跨步的迈向移动互联网了,更何况Web App也应用广泛,可能原理还一样,但是一定会有新的东西出现,那就从“头”开始,看看头部那些Meta的新玩意. ...