poj-2369-置换】的更多相关文章

题目链接 给一个数列, 求这个数列置换成1, 2, 3....n需要多少次. 就是里面所有小的置换的长度的lcm. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #inclu…
题意:给你一堆无序的数列p,求k,使得p^k=p 思路:利用置换的性质,先找出所有的循环,然后循环中元素的个数的lcm就是答案 代码: #include <cstdio> #include <cstring> #include <iostream> #define maxn 1234 using namespace std; int gcd(int a,int b) { ) return a; else return gcd(b,a%b); } int lcm(int…
题意 给定一个置换形式如,问经过几次置换可以变为恒等置换 思路 就是求k使得Pk = I. 我们知道一个置换可以表示为几个轮换的乘积,那么k就是所有轮换长度的最小公倍数. 把一个置换转换成轮换的方法也很简单,从一个数出发按照置换图置换,直到置换到已经置换过的数,则这些数就构成一个轮换. 代码 [cpp] #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #i…
We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows:  This record de…
poj 置换的应用 黑书原题P248 /** 题意: 给定序列, 将其按升序排列, 每次交换的代价是两个数之和, 问代价最小是多少 思路:1.对于同一个循环节之内的,肯定是最小的与别的交换代价最小 2. 对于整个序列中最小的与其交换 ,也可能最小 比较这两个大小,即可得出结论 对于情况1:代价为 sum+(len-2)*t //len 为每个循环节的长度, t 为每个循环节中最小的那个数 sum 为循环节中所 有数的和 对于情况2: 代价: sum+t+(len+1)*min // m为整个序列…
Description We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder elements of the set. For example, one can define a permutation of the set {1,2,3,4,5} as follows:  Th…
傻逼图论. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxv 1050 #define maxn 1050 #define maxe 2050 using namespace std; ,g[maxv],ans[maxn],sum=,cnt=; bool vis[maxn]; struct edge { int v,nxt; }e[ma…
寻找循环节求lcm够了,如果答案是12345应该输出1.这是下一个洞. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; #define INF 0x3FFFFFF #define MAXN 2222 #define eps 1e-…
Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3041   Accepted: 1641 Description We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formally, that is a way to reorder eleme…
经典的题目,主要还是考思维,之前在想的时候只想到了在一个循环中,每次都用最小的来交换,结果忽略了一种情况,还可以选所有数中最小的来交换一个循环. Cow Sorting Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6511   Accepted: 2532 Description Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the…