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 ——置换群的更多相关文章

  1. POJ2369 Permutations【置换群】

    题目链接: http://poj.org/problem?id=2369 题目大意: 给定一个序列.问最少须要多少次置换才干变为 1.2.-.N 的有序序列.比方说给 定5个数的序列 4 1 5 2 ...

  2. POJ2369 Permutations(置换的周期)

    链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  3. POJ 2369 Permutations(置换群概念题)

    Description We remind that the permutation of some final set is a one-to-one mapping of the set onto ...

  4. Uva 11077 Find the Permutations [置换群 DP]

    题意: 给定$n$和$k$,问有多少排列交换$k$次能变成升序 $n \le 21$ $uva$貌似挂掉了$vjudge$上一直排队 从某个排列到$1,2,...,n$和从$1,2,...,n$到某个 ...

  5. POJ置换群入门[3/3]

    POJ 3270 Cow Sorting 题意: 一个序列变为升序,操作为交换两个元素,代价为两元素之和,求最小代价 题解: 看了黑书... 首先循环因子分解 一个循环完成的最小代价要么是循环中最小元 ...

  6. acm数学(待续)

    意图写出http://www.cnblogs.com/kuangbin/archive/2012/08/28/2661066.html这个东西的完善版. 1.置换,置换的运算 poj 2369 Per ...

  7. poj1026 Cipher ——置换群

    link:http://poj.org/problem?id=1026 其实这道题目和poj2369这道题目一样. 都是基础的置换群题目.把那道题目理解了,这道题就没问题了. 不过我的方法貌似比较挫, ...

  8. poj 2369(置换群)

    Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3041   Accepted: 1641 Desc ...

  9. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

随机推荐

  1. hdu 3887 Counting Offspring dfs序+树状数组

    Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. 单据BE构建

    本节来构建单据BE1.新建单据BE实体项目,修改命名空间 2.引入单据基类如下图所示,在UFIDA.U9.Base.BaseBE.MetaData命名空间下将类Doc托至设计BE视图中 3.分别托2个 ...

  3. kd tree学习笔记 (最近邻域查询)

    https://zhuanlan.zhihu.com/p/22557068 http://blog.csdn.net/zhjchengfeng5/article/details/7855241 KD树 ...

  4. 从原理上理解NodeJS的适用场景

    NodeJS是近年来比较火的服务端JS平台,这一方面得益于其在后端处理高并发的卓越性能,另一方面在nodeJS平台上的npm.grunt.express等强大的代码与项目管理应用崛起,几乎重新定义了前 ...

  5. DELETE与TRUNCATE的区别

    当执行 DELETE FROM TABLE后,会发现针对一个DELETE语句,该表中有多少行内容,数据库日志文件中,相对应的记录是就是多少条,每一条记录,对应的是行级别的删除.而且对应的LSN编号也是 ...

  6. android mvvm

    android studio 需要gradle 1.5.0以上才支持 dependencies { classpath 'com.android.tools.build:gradle:1.5.0'} ...

  7. 超级迷宫 nabc

    特点之一:益智模式 N  我们的游戏需要一点点益智答题使其精彩 A 在走迷宫的过程中,会遇到某一个点,出现一个益智小问题,答对即可通过 B 增加游戏的趣味性,吸引用户 C 答题游戏不少,前不久腾讯的手 ...

  8. C语言输出时的各种%

    d  以十进制形式输出带符号整数(正数不输出符号) o  以八进制形式输出无符号整数(不输出前缀O) x  以十六进制形式输出无符号整数(不输出前缀OX) u  以十进制形式输出无符号整数 f  以小 ...

  9. C关键字

    1 extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义

  10. 读<jquery 权威指南>[4]-Ajax

    一.获取异步数据 jQuery可以从服务器异步获得静态数据. ①load() $.load(url,data,callback) url要加载的页面地址, data发送到服务器的数据key/value ...