博客
关于我
例题8-1 UVA - 120
阅读量:633 次
发布时间:2019-03-14

本文共 1098 字,大约阅读时间需要 3 分钟。

 Stacks of Flapjacks  UVA - 120

/*算法竞赛入门 LRJ 例题8-1 UVA - 120*/#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long LL;using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")const double eps = 1e-6;const int INF=0x3f3f3f3f;const int N = 1010;const int PI = acos(-1.0);int a[N],b[N];bool cmp(int x,int y){ return x > y;}void handle(int l,int r){ while(l < r) { int temp = a[l]; a[l] = a[r]; a[r] = temp; l++; r--; }}int main(){ int n = 0; char c; while(~scanf("%d%c",&a[++n],&c)) { while(c == ' ') scanf("%d%c",&a[++n],&c); for(int i = 1 ;i <= n; i++) { // b[i] = a[i]; if(i == n) printf("%d\n",a[i]); else printf("%d ",a[i]); } handle(1,n); for(int i = 1 ;i <= n; i++) b[i] = a[i]; sort(b+1,b+n+1,cmp); for(int i = 1; i <= n; i++) { //printf("%d ",b[i]); if(b[i] == a[i]) continue; int temp; for(int j = i+1; j <= n; j++) if(b[i] == a[j]) temp = j; if(temp != n) { printf("%d ",temp); handle(temp,n); temp = n; } printf("%d ",i); handle(i,temp); } printf("0\n"); n = 0; } return 0;}

转载地址:http://gcaoz.baihongyu.com/

你可能感兴趣的文章
mysql查询慢排查
查看>>
MySQL查询报错ERROR:No query specified
查看>>
mysql查询数据库储存数据的占用容量大小
查看>>
MySQL查询数据库所有表名及其注释
查看>>
MySQL查询数据表中数据记录(包括多表查询)
查看>>
MySQL查询结果排序
查看>>
MYSQL查询语句优化
查看>>
mysql查询语句能否让一个字段不显示出来_天天写order by,你知道Mysql底层执行原理吗?
查看>>
MySQL查询语句:揭秘专家秘籍,让你秒变数据库达人!
查看>>
mysql查询超时对PHP执行的影响
查看>>
mysql查询输出到excel文件_如何保存mysql查询输出到excel或.txt文件?
查看>>
mysql查询过程
查看>>
MySQL模拟Oracle序列sequence
查看>>
Mysql模糊查询like效率,以及更高效的写法
查看>>
MySQL死锁套路:一次诡异的批量插入死锁问题分析
查看>>
Mysql死锁问题Deadlock found when trying to get lock;try restarting transaction
查看>>
mysql每个数据库的最大连接数_MySQL数据库最大连接数
查看>>
Mysql流程控制结构,if函数、case结构、if结构、循环结构
查看>>
mysql添加外网访问权限
查看>>
mysql添加用户
查看>>