题目大意:给出1~n的某个排列,问由升序变到这个排列最少需要几次操作.操作1:将头两个数交换:操作2:将头一个数移动最后一个位置. 题目分析:反过来考虑,将这个排列变为升序排列,那么这个变化过程实际上就是冒泡排序的过程.将这个排列视为环形的,操作1为交换过程,操作2为查找逆序对的过程.那么,将升序排列变成给出的排列就是打破顺序的过程,或者说是还原为无序的过程.那么只需要将冒泡排序的过程逆过来即可,将操作2中“将头上的数移到尾上”改为“把最后一个数移到最前面”,最后将操作过程倒序输出即可. 代码如…
逆序做,逆序输出 紫书上的描述有点问题 感觉很经典 ans.push_back(2); a.insert(a.begin(),a[n-1]); a.erase(a.end()-1); a.push_back(k);vector 的操作 没有证明这样做的复杂度要求... #include<cstdio> #include<algorithm> #include<vector> using namespace std; int n; vector<int> a,…
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ...,…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud ZZX and Permutations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 181    Accepted Submission(s): 38 Problem Description ZZX likes…
D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transfo…
ZZX and Permutations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 24    Accepted Submission(s): 2 Problem Description ZZX likes permutations. ZZX knows that a permutation can be decomposed…
H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description You are given a set Y of ndistinct positive integers y1, y2, ..., yn. Set X of ndistinct positive integers x1, x2, ..., xn is…
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a set Y of n distinct positive integers y1, y2, ..., yn. Set X of n distinct positive integers x1, x2, ...,…
留坑(p.254) #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> using namespace std; void setIO(const string& s) { freopen((s + ".in").c_str(), "r", stdin); freope…
题意: 给出一个1到n的排列,给出操作顺序,使升序排列能变为所给排列. 分析: 正常冒泡排序的想法.如果前两个数,前面的大于后面的,则换(特例是n,1不能换).否则,就用2的逆操作,把最后的数放前面.不过用了vector数组存放 代码: #include <iostream>#include <cstdio>#include <algorithm>#include <vector>using namespace std;int n;vector<int…