UVa11925 Generating Premutations
留坑(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);
freopen((s + ".out").c_str(), "w", stdout);
}
template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} const int N = + ; #include<vector>
vector<int> a, b; //#define dprintf(s, arg...) fprintf(stderr, s, ##arg) void p1() {
swap(a[], a[]);
putchar('');
// dprintf("1:");
// for(unsigned i = 0; i < a.size(); i++) {
// dprintf("%d ", a[i]);
// }
// dprintf("\n");
} void p2() {
int t = a[];
a.erase(a.begin());
a.push_back(t);
putchar('');
// dprintf("2:");
// for(unsigned i = 0; i < a.size(); i++) {
// dprintf("%d ", a[i]);
// }
// dprintf("\n");
} bool ok() {
for(unsigned i = ; i < a.size(); i++) {
if(a[i] ^ b[i]) return ;
}
return ;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int n;
while(read(n)) {
a.clear(), b.clear();
for(int i = ; i <= n; i++) {
a.push_back(i);
b.push_back(read<int>());
}
if(a[] == b[]) p1();
for(int i = ; i < n; i++) {//½«µÚi¸öÒÆµ½×îºó
while(a[] != b[i]) p2();
if(ok()) break;
if(i != n-) while(a[] != b[i+]) p1(), p2();
p2();
}
putchar('\n');
// dprintf("\n");
} return ;
}
UVa11925 Generating Premutations的更多相关文章
- UVA-11925 Generating Permutations (逆向思维)
题目大意:给出1~n的某个排列,问由升序变到这个排列最少需要几次操作.操作1:将头两个数交换:操作2:将头一个数移动最后一个位置. 题目分析:反过来考虑,将这个排列变为升序排列,那么这个变化过程实际上 ...
- uva11925 Generating Permutations
逆序做,逆序输出 紫书上的描述有点问题 感觉很经典 ans.push_back(2); a.insert(a.begin(),a[n-1]); a.erase(a.end()-1); a.push_b ...
- Codeforces 722D. Generating Sets
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Xcode8 pod install 报错 “Generating Pods project Abort trap
Xcode8 pod install 报错 "Generating Pods project Abort trap 今天在写一个新项目的时候,使用cocoapods在执行 $ pod ins ...
- CF722D. Generating Sets[贪心 STL]
D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- The resource identified by this request is only capable of generating responses with characteristics
[转]今天在调试springMVC的时候,在将一个对象返回为json串的时候,浏览器中出现异常: The resource identified by this request is only cap ...
- Auto generating Entity classes with xsd.exe for XML Serialization and De-Serialization
More info here: http://blogs.msdn.com/b/yojoshi/archive/2011/05/14/xml-serialization-and-deserializa ...
- ORA-1461 encountered when generating server alert SMG-3500
Doc ID 461911.1 Patch 6602742 Applies to: Oracle Database - Enterprise Edition - Version 10.2.0.3 an ...
- 读书笔记 1 of Statistics :Moments and Moment Generating Functions (c.f. Statistical Inference by George Casella and Roger L. Berger)
Part 1: Moments Definition 1 For each integer $n$, the nth moment of $X$, $\mu_n^{'}$ is \[\mu_{n}^{ ...
随机推荐
- 冒泡排序(C++)
冒泡排序(C++) 冒泡排序(C++): 原理是临近的数字两两进行比较,按照从小到大或者从大到小的顺序进行交换, 这样一趟过去后,最大或最小的数字被交换到了最后一位, 然后再从头开始进行两两比较交换, ...
- oracle查看用户信息
1.查看所有用户:select * from dba_users; select * from all_users; select * from user_users;2.查看用户或角色系统权限(直接 ...
- php时间选择器亲测可以自己修改
由于前端的离职 造成我需要自己去做后台页面 所以有一个要填写生日的我就用了这个时间选择器 <?php /** * Created by PhpStorm. * User: Administ ...
- #Leet Code# Divide Two Integers
描述:不使用 * / % 完成除法操作.O(n)复杂度会超时,需要O(lg(n))复杂度. 代码: class Solution: # @return an integer def dividePos ...
- Amazon's NoSQL Journey and AWS Operations
AWS: Amazon Web Services 提供了一整套基础设施和应用程序服务,使您几乎能够在云中运行一切应用程序:从企业应用程序和大数据项目,到社交游戏和移动应用程序. 计算类: EC2:弹性 ...
- QML之TextEdit
TextEdit显示一个可编辑的,有格式的文本框.它也可以显示明文和富文本.例如:TextEdit { width: 240 text: "<b>Hello</ ...
- VPN ,Bypass the FIrewall
Bypass the China Firewall Methods November 16th, 2012Posted in , Tech With their assortment of techn ...
- awk 多分隔符
#!/bin/bash log_path="./log/" dates=`date -d '-1 days' +'%Y%m%d'` cd $log_path; for i in ` ...
- secureCRT使用小贴士
(一)使用WIN键盘 在securecrt界面:工具→键映射编辑器,在弹出的键盘中点击“home”,会弹出一个窗口,在“发送字符串”中输入:\033[1~ 另存为securecrt安装根目录下的Key ...
- 常用webservice接口案例
商业和贸易: 1.股票行情数据 WEB 服务(支持香港.深圳.上海基金.债券和股票:支持多股票同时查询) Endpoint: http://webservice.webxml.com.cn/WebSe ...