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}^{ ...
随机推荐
- Ubuntu 源
原文地址: Ubuntu 12.04添加源 sudo vim /etc/apt/sources.list #网易163 deb http://mirrors.163.com/ubuntu/ preci ...
- sql 命令操作用法
---恢复内容开始--- 远程登录数据库: mysql -u root -p 要求输入密码 ============== 查看数据库: show databases;============= 选择数 ...
- Android Binder机制简单了解
Binder -- 一种进程间通信(IPC)机制, 基于OpenBinder来实现 毫无疑问, 老罗的文章是不得不看的 Android进程间通信(IPC)机制Binder简要介绍和学习计划 浅谈Ser ...
- iOS: 学习笔记, 值与引用类型(译自: https://developer.apple.com/swift/blog/ Aug 15, 2014 Value and Reference Types)
值和引用类型 Value and Reference Types 在Swift中,有两种数据类型. 一是"值类型"(value type), 它是每一个实例都保存有各自的数据,通常 ...
- 练习2 E题 - 求奇数的乘积
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 给你n ...
- 【UVA10829】 L-Gap Substrings (后缀数组)
Description If a string is in the form UVU, where U is not empty, and V has exactly L characters, we ...
- Eclipse的设置小细节提高开发效率
1. 自动联想功能增强 preference->java->Editor->Content Assist中, Auto activation triggers for java中默认 ...
- win7 热点设置命令
netsh wlan set hostednetwork mode=allownetsh wlan set hostednetwork ssid=XXXX key=XXXnetsh wlan star ...
- 注意android裁图的Intent action
现在很多开发者在裁图的时候还是使用com.android.camera.action.CROP 来调用 startActivity(). 这不是个好主意. 任何不是依android开头的Action ...
- 2.5.1 使用alertDialog
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...