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. SQL Server 查询表的记录数(3种方法,推荐第一种)

    http://blog.csdn.net/smahorse/article/details/8156483 --SQL Server 查询表的记录数 --one: 使用系统表. SELECT obje ...

  2. XDocument 获取包括第一行的声明(版本、编码)的所有节点

    XDocument保存为xml文件的方法如下: XDocument doc = new XDocument( new XDeclaration("1.0","UTF-8& ...

  3. 剑指offer一:二维数组中的查找

    题目: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 思路: 这是一个顺序二维 ...

  4. loadrunner常用术语

    1.场景 在loadrunner中主要表现为controller中设计与执行测试用例中的用户场景.主要工作有,在controller中选择虚拟用户脚本.设置虚拟用户数量.配置虚拟用户运行时的行为.选择 ...

  5. 自定义弹出框基于zepto 记得引入zepto

    html <!DOCTYPE html> <html> <meta charset="utf-8"> <title></tit ...

  6. Div的宽度与高度的100%设定

    div的100%是从其上一级div的宽高继承来的,所以必须设置其上一级div的宽度或高度,否则无效. 举例说明:父div(deman)宽300高200,子div(cc)如果在这个条件下设置divcc的 ...

  7. JQuery_过滤选择器

    一.基本过滤器 1.基本过滤器 过滤器主要通过特定的过滤规则来筛选所需的 DOM 元素,和 CSS 中的伪类的语法类似:使用冒号(:)开头. <script type="text/ja ...

  8. CentOS 7 中设置启动模式

    1.命令行模式systemctl set-default multi-user.target2.图形模式systemctl set-default graphical.target

  9. java的concurrent用法详解

    我们都知道,在JDK1.5之前,Java中要进行业务并发时,通常需要有程序员独立完成代码实现,当然也有一些开源的框架提供了这些功能,但是这些依然没有JDK自带的功能使用起来方便.而当针对高质量Java ...

  10. flash透明效果代码分享~~~

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...