uva 120 Stacks of Flapjacks 煎饼
2016-02-23 21:54
330 查看
先放好第K大的煎饼,然后放好k-1大的煎饼。
因为如果要放对第k-1大的煎饼的位置,所有被变更位置的煎饼一定在区间[1,k-1]内,不会影响到刚才放好的第k大煎饼。
因为如果要放对第k-1大的煎饼的位置,所有被变更位置的煎饼一定在区间[1,k-1]内,不会影响到刚才放好的第k大煎饼。
/**========================================== * This is a solution for ACM/ICPC problem * * @source£º * @type: * @author: wust_ysk * @blog: http://blog.csdn.net/yskyskyer123 * @email: 2530094312@qq.com *===========================================*/ #include<cstdio> #include<string> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<sstream> using namespace std; typedef long long ll; const int INF =0x3f3f3f3f; const int maxn=30 ; int n,cnt; struct A { int num; bool operator<(const A y)const { return num<y.num; } }a[maxn+5],b[maxn+5]; int pos; string s; void print(int x) { if(cnt++) putchar(' '); printf("%d",n+1-x); } void get(int k) { if(pos==k) return ; if(pos==1) { print(k); reverse(a+1,a+k+1); return; } print(pos); reverse(a+1,a+pos+1); print(k); reverse(a+1,a+k+1); } void work() { memcpy(b,a,sizeof a); sort(b+1,b+1+n); for(int i=n;i>=1;i--) { int maxi=-1; for(int j=1;j<=i;j++) { if(a[j].num>maxi) { maxi=a[j].num; pos=j; } } get(i); } print(n+1-0); putchar('\n'); } int main() { while(getline(cin,s)) { n=0; cnt=0; stringstream ss(s); while(ss>>a[++n].num) { if(n!=1) putchar(' '); printf("%d",a .num); } putchar('\n'); n--; work(); } return 0; }
相关文章推荐
- 一张图看清Linux 内核运行原理
- Java 中读写文件内容常见的几种方法
- STM32问题集之头函数路径报错
- 老男孩27期学员-我的目标
- 我的笔记:精通JAVA集合类
- 最大子段和||最大子矩阵和||最大全1子矩阵||最大全1子正方形||
- linux 安装svn
- 通过HttpURLConnection获得服务器的数据简单模型
- 如何找出记录表中某列记录数大于N
- 如何利用css让元素居中
- POJ2115 C Looooops 模线性方程(扩展欧几里得)
- REUSEADDR 选项
- Eclipse 快捷键大全
- 微信jsapi支付开发遇到的坑
- Linux下判断网线是否插入的代码
- Cimage类的介绍及使用
- Unicode令人混淆的概念
- 运算符重载4(有指针成员指向动态内存时)
- MapReduce网站基本指标编程
- 滑动删除