CF(441D Valera and Swaps)置换群】的更多相关文章

题意:1-n的一个排列, p2, ..., pn,f(p)的定义是此排列要交换最少的数对能够回到原排列1,2,3,4...n.给一个排列p.要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典序最小的那组答案. 解法:处理出全部的置换群,求出环数k,此时f值为n-k.然后推断n-k和m的大小,分为两种操作 1.加环,这个是在随意元素个数大于1的环内交换随意两个数都能够做到加环 2.减环,交换随意两个环的随意两个元素.就能够做到将两个环连接起来 题目要求是输出字典序最小,那么就暴力搞. 代…
题意: 给定一个1~n的排列(n<=3000),输出字典序最小且次数最少的交换操作,使得操作后的排列可以通过最少m次交换得到排列[1,2,...n] Solution: 可以将排列的对应关系看做边,f[i]=i,代表自环.那么根据置换原理,图中有k个环,则需要最少n-k次交换操作得到排列[1,2...n].所以,先找出图中的环,对同一个环的位置进行标记.这样对不在同一个环的两个位置进行交换,会将两个环合并.将在同一个环内的两个位置进行交换,会将这个环分成两个环. 只需要,判断需要加环还是去环.贪…
A permutation p of length n is a sequence of distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). A permutation is an identity permutation, if for any i the following equation holds pi = i. A swap (i, j) is the operation that swaps elements pi and pj in t…
C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's…
CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个数. Solution 设\(f[i][j]\)为执行第\(i\)次后\(x + j\)末尾期望\(0\)的个数 加一:$f[i + 1][j - 1] = f[i + 1][j - 1] + (100 - p)% * f[i][j]; $ 乘二:\(f[i + 1][j * 2] = f[i +…
题意: 定义 $f(p)$ 表示将 $p$ 序列变换为有序序列最少要交换多少次,给一 $1 \sim n$ 的排列 $a$ ,给一整数 $m$, 求问将 $a$ 最少交换多少次能得到 $p$ ,使得 $f(p) = m$,并将以此交换视作一个两个数字,将交换按顺序排列开 求出字典序最小的交换序列. 解法: 记 $id$ 表示排列 $id(i) = i$ 考虑 $f(p)$ 怎么求,可以发现,将原排列视作一个从$p$置换到$id$的置换,则将置换拆分成 $tot$ 个循环后, 最小交换次数就是$\…
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. 思路:求出没有被点的覆盖的线段的个数,n-这个个数就是所求的. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 2000000 using namespace std; ; int…
http://codeforces.com/contest/369/problem/D 标号最小的两个人会有四种状态:a活b活,a死b活,a活b死,a死b死:按照这四种状态dfs就可以求出最后的数量. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 5000 using namespace std; int n,k; int ans; int p[maxn]; bool vis…
http://codeforces.com/contest/369/problem/C 先见边,然后dfs,在回溯的过程中,如果在这个点之后有多条有问题的边,就不选这个点,如果没有而且连接这个点的边还是有问题的边,这个点就是所求的点. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 200000 using namespace std; int head[maxn],e,cnt…
http://codeforces.com/contest/369/problem/B 先对k个处理,先处理sk%k个为sk/k+1,如果sk/k==0,k个数都为sk/k:对与剩下的数也按照同样的方法处理,处理完之后就是所要求的序列. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 10000 using namespace std; int n,k,l,r,s1,s2; i…