博客
关于我
例题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 sum 没返回,如果没有找到任何值,我如何在MySQL中获得SUM函数以返回'0'?
查看>>
mysql Timestamp时间隔了8小时
查看>>
Mysql tinyint(1)与tinyint(4)的区别
查看>>
mysql union orderby 无效
查看>>
mysql v$session_Oracle 进程查看v$session
查看>>
mysql where中如何判断不为空
查看>>
MySQL Workbench 使用手册:从入门到精通
查看>>
mysql workbench6.3.5_MySQL Workbench
查看>>
MySQL Workbench安装教程以及菜单汉化
查看>>
MySQL Xtrabackup 安装、备份、恢复
查看>>
mysql [Err] 1436 - Thread stack overrun: 129464 bytes used of a 286720 byte stack, and 160000 bytes
查看>>
MySQL _ MySQL常用操作
查看>>
MySQL – 导出数据成csv
查看>>
MySQL —— 在CentOS9下安装MySQL
查看>>
MySQL —— 视图
查看>>
mysql 不区分大小写
查看>>
mysql 两列互转
查看>>
MySQL 中开启二进制日志(Binlog)
查看>>
MySQL 中文问题
查看>>
MySQL 中日志的面试题总结
查看>>