[题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出交换顺序. [题解] 我们发现对于四个一组组内进行六次交换之后可以保证四个数的位置不变, 而对于每组相互之间可以一共进行十六次交换使得两组均不会发生变化 所以如果n能被4整除,那么我们可以4个分组达到目的, 当不能被4整除的时候,我们发现余数为2和3的时候都不能构造出可行解. 在余数为1的时候有一种…
题目链接 假设始终可以找到一种状态使得值为0, 那么两个1之间需要隔n-2个数, 两个2之间需要隔n-3个数, 两个3之间隔n-4个数. 我们发现两个三可以放到两个1之间, 同理两个5放到两个3之间....这样就构造好了. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmat…
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) i…
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi…
B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/problem/B Description Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from…
这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ................... \  /        \  /           \  / k          k-1          k-2 如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2 这样下来,最后一个数字就是一个中间的数字,过程就…
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的绝对值为单调递减序列..... 如果够k个了,最后将没有访问到的元素直接添加到末尾! #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 1000…
题目链接 \(Description\) 给定一个\(n\)的排列\(p_i\),求一个排列\(q_i\),使得对于任意\(1\leq i\leq n\),\(q_{q_i}=p_i\).无解输出\(-1\). \(1\leq n\leq10^6\). \(Solution\) 对排列\(q_i\)我们建一张图,边为\(i\to q_i\).显然这张图是由几个环构成. 发现对于\(q_{q_i}\)的图,原来\(q_i\)中的奇环它们还是类似的一个奇环,原来的偶环会分裂成两个大小相等的偶环. 所…
题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这个排列上的数与它所在位置的序号的最大公约数满足 > 1,并且这些数的个数恰好满足k个,输出这样的一个排列. 先说明什么时候得不到这样的一个排列,就是n = k的情况.因为任何一个数x放在第1个位置的gcd(x, 1) = 1的,所以要得出这样一个排列 k 最大只能为 n-1 .而k最小为0个,这个排…
Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 691D Description You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj). At each step you can choose a…