摘要: 一开始直接模拟,果断超时了,后来上网查了查,是组合数学中的置换群。本题求经过多少次置换P能变成初始状态。对于任意一个[1,n]的数字,经过多次置换后一定可以变会初始状态,而且置换的次数不会超过n。对于第i个数,模拟计算出其置换周期,记为ai,答案就是所有ai的最小公倍数。 1 2 3 4 5 4 1 5 2 3次数:3 3 2 3 2,最小公倍数6. 1 #include <iostream> 2 #include <cstdio> 3 int gcd(int a, int b) 4 { 5 if (b == 0) 6 return a; 7 else ... 阅读全文
posted @ 2013-04-07 11:50 PegasusWang 阅读(294) 评论(0) 推荐(0)