poj2369 Permutations ——置换群
2024-10-14 07:31:29
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找循环节么。很神奇的样子。
多多模拟一下,严格的证明貌似还要好好看一下近世代数。
嗨,中村
最新文章
- Visaul Studio 常用快捷键的动画演示
- 导出BOM表
- Sublime Text 3 文本编辑器
- apache下ab.exe使用方法。。
- ios7.0结合storyborad实现页面跳转的总结
- [置顶] VC++界面编程之--使用分层窗口实现界面皮肤
- 【Java规划】DOM XML Parser分解、遍历、创XML
- 32.Spring-对象依赖.md
- cocos2dx中Action汇总
- Android单元测试Junit (一)
- java人员正确使用IDEA 的方式
- Jquery字符串,数组(拷贝、删选、合并等),each循环,阻止冒泡,ajax出错,$.grep筛选,$.param序列化,$.when
- java 集合框架(十六)Map
- qt+vs2017环境下XIMEA相机库的配置
- 【BZOJ4030】[HEOI2015]小L的白日梦
- 基于Zookeeper实现多进程分布式锁
- 尝鲜svnup
- 14-background
- 【题解】Luogu UVA12345 Dynamic len(set(a[L:R]))
- python pipe stdout 实现cat|grep 功能
热门文章
- 《BI那点儿事》数据流转换——审核
- AngularJS 特性—SinglePage、template、Controller
- 关于js touch事件 的引用设置
- openssl证书相关
- excel模版从xp复制到win7系统后出现错误 运行时错误 &#39;429&#39; ActiveX 部件不能创建对象
- jquery validate 在ajax提交表单下的验证方法
- 安卓手机上运行 PC-E500 程序
- no leveldbjni64-1.8 in java.library.path
- JfreeChart的使用
- 父类方法中的this