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. Sprint(第四天11.17)

    燃尽图

  2. Oracle PL/SQL实战代码下载

    最近在学习PL/SQL编程,算是一个进阶吧,书没带光盘,所以按照书中的地址去下载样例,无法下载,到图灵官网找到了源代码下载地址,无法下载的留邮箱,我发给大家 下载地址: http://www.itur ...

  3. sublime_text3配置

    推荐视频 http://v.youku.com/v_show/id_XMzU5NzQ5ODgw.html 介绍的是2版本 准备工作 点击连接下载Sublime Text3 初始化用户信息 第一次安装该 ...

  4. SPI总线(同步)

    一.SPI总线简介 串行外围设备接口SPI(serial peripheral interface)总线技术是Motorola公司推出的一种同步串行接口.SPI 用 于CPU与各种外围器件进行全双工. ...

  5. block(闭包)

    使用方式 1定义为类的属性 最后用来发布通知,执行block即可 甚至同时发送数据参数,给方法调用者,这样返回数据比返回值形式,更好, 因为这样传参,不是同步的,而是异步响应式的,更加灵活安全. 2定 ...

  6. Linux Socket编程(不限Linux)

    "一切皆Socket!" 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. --有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信 ...

  7. Sprint2-3.0

    后续安排 第16周 周二晚7点之前将本代码上传到GITHUB. GITHUB地址:https://github.com/QueenIcey/teamwork/tree/master/eslife1 周 ...

  8. 【转】十分钟搞定pandas

    原文链接:http://www.cnblogs.com/chaosimple/p/4153083.html 关于pandas的入门介绍,比较全,也比较实在,特此记录~ 还有关于某同学的pandas学习 ...

  9. 回顾CSS布局易混淆的概念

    一.浮动模型 元素默认是static的,不能浮动,但可以用CSS样式设置为浮动 浮动模型只有两个值 float:left 和 float:right ,可以让块状元素同行显示 二.层模型 top/bo ...

  10. Objective-C( Foundation框架 一 常见的结构体)

    常见的结构体 (NSPoint,CGPoint).(NSRange,CGRange).(NSSize,CGSize) 苹果官方推荐使用CG开头的结构体 NSRange是Foundation框架中常见的 ...