留坑(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的更多相关文章

  1. UVA-11925 Generating Permutations (逆向思维)

    题目大意:给出1~n的某个排列,问由升序变到这个排列最少需要几次操作.操作1:将头两个数交换:操作2:将头一个数移动最后一个位置. 题目分析:反过来考虑,将这个排列变为升序排列,那么这个变化过程实际上 ...

  2. uva11925 Generating Permutations

    逆序做,逆序输出 紫书上的描述有点问题 感觉很经典 ans.push_back(2); a.insert(a.begin(),a[n-1]); a.erase(a.end()-1); a.push_b ...

  3. Codeforces 722D. Generating Sets

    D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Xcode8 pod install 报错 “Generating Pods project Abort trap

    Xcode8 pod install 报错 "Generating Pods project Abort trap 今天在写一个新项目的时候,使用cocoapods在执行 $ pod ins ...

  5. CF722D. Generating Sets[贪心 STL]

    D. Generating Sets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 读书笔记 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}^{ ...

随机推荐

  1. 3D math primer for graphics and game development

    三角网格(Triangle Mesh) 最简单的情形,多边形网格不过是一个多边形列表:三角网格就是全部由三角形组成的多边形网格.多边形和三角网格在图形学和建模中广泛使用,用来模拟复杂物体的表面,如建筑 ...

  2. diff函数的实现——LCS的变种问题

    昨天去去哪儿笔试,碰到了一个我们一直很熟悉的命令(diff——ubuntu下面),可以比较字符串,即根据最长公共子串问题,如果A中有B中没有的字符输出形式如下(-ch),如果A中没有,B中有可以输出如 ...

  3. 基础-函数3(IIFE立即执行函数)

    参考链接: http://benalman.com/news/2010/11/immediately-invoked-function-expression/#iife http://segmentf ...

  4. jquery 幻灯片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. HTML5 自适应rem布局

    (function(doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? ' ...

  6. 1.document.write(""); 输出语句

    1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...

  7. power designer中查看表sql去掉字段属性双引号设置

    把Database → Edit Current DBMS → General → Script → Sql → Format → CaseSensitivityUsingQuote设置为NO

  8. ubuntu chm文档阅读

    四种方法在Ubuntu下查看CHM文件 来源:http://os.51cto.com/art/201108/287748.htm Ubuntu是一个以桌面应用为主的Linux操作系统,刚开始使用Ubu ...

  9. uboot 连接脚本分析

    一.脚本分析 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm ...

  10. (转)Eclipse 下找不到或无法加载主类的解决办法

    转自:http://my.oschina.net/leejun2005/blog/106789,写的太好了! 有时候 Eclipse 会发神经,好端端的 project 就这么编译不了了,连 Hell ...