留坑(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 Game Programming with directx 11 习题答案 8.3

    第八章 第三题 1.将flare.dds和flarealpha.dds拷贝到工程目录 2.创建shader resource view HR(D3DX11CreateShaderResourceVie ...

  2. 笔记一:Python的PyDev插件在eclipse上面安装(新的插件地址 location)

    注:部分内容参考网上的,若有侵权,请作者联系我,马上进行删改 安装PyDev: 首先需要去Eclipse官网下载:http://www.eclipse.org/,Eclipse需要JDK支持,如果Ec ...

  3. [转]Python核心模块——urllib模块

    现在Python基本入门了,现在开始要进军如何写爬虫了! 先把最基本的urllib模块弄懂吧. urllib模块中的方法 1.urllib.urlopen(url[,data[,proxies]]) ...

  4. android关于installLocation

    以下内容主要参考自官网的描述. 从Android API-8开始,android允许你将应用程序安装到外部存储空间中去(比方:SD卡),你可以在AndroidManifest.xml中添加androi ...

  5. HttpWebRequest 写入报错

    HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size ...

  6. nesC 语言参考手册

    1 简介 nesC 是对 C 的扩展 ,它基于体现 TinyOS 的结构化概念和执行模型而设计. TinyOS 是为传感器网络节点而设计的一个事件驱动的操作系统,传感器网络节点拥有非常有限的资源 ( ...

  7. python ^M 产生的原因 及 lxml 如何获取text的原因

    其实跟踪一下会发现,^M 是由于 /r/n 所造成的. article = dom_c.xpath('//td[@id="article_content"]//text()')co ...

  8. Nosql database

    http://kb.cnblogs.com/page/42731/ http://nosql-database.org/ http://blog.jobbole.com/1344/ http://ww ...

  9. JSON和XML:不可同日而语

    [编者按]本文作者 Yegor Bugayenko 是 Teamed.io 公司的联合创始人,在软件质量和工程管理方法领域有深入的研究.本文中,作者通过对比 JSON ,向大家更详细地阐述了 XML ...

  10. KeilC51高级编程

    第一节 绝对地址访问 C51提供了三种访问绝对地址的方法: 1. 绝对宏: 在程序中,用“#include<absacc.h>”即可使用其中定义的宏来访问绝对地址,包括: CBYTE.XB ...