【UVa120】Stacks of Flapjacks 模拟
来源:互联网 发布:c语言 线程优先级 编辑:程序博客网 时间:2024/06/07 07:01
原题:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=56
题意:给定一个序列,每次可以选一个数使数列第一个到这个数颠倒,问如何颠倒使最后数列升序。
先将每个数升序后要呆的位置确定好,然后将这个数翻到最上面再翻到这个位置。
#include<iostream>#include<algorithm>#include<sstream>#include<cstring>#include<cstdio>using namespace std;int tot;string s;int a[55];void flip(int p){for (int i=0;i<p-i;i++) swap(a[i],a[p-i]);printf("%d ",tot-p);}int main(){while(getline(cin,s)){tot=0;cout<<s<<endl;stringstream ss(s);while(ss>>a[tot])tot++;for (int i=tot-1;i>0;i--){int pos=max_element(a,a+i+1)-a;//max_element返回的是迭代器if (pos==i) continue;if (pos>0) flip(pos);//如果已经在最上面的位置就不需要翻了flip(i);}printf("0\n");}return 0;}
阅读全文
0 0
- 【UVa120】Stacks of Flapjacks 模拟
- uva120 stacks of flapjacks
- uva120 Stacks of Flapjacks
- uva120 Stacks of Flapjacks
- UVA120 Stacks of Flapjacks
- UVa120 Stacks of Flapjacks
- UVA120 - Stacks of Flapjacks
- UVa120 - Stacks of Flapjacks (STL)
- Uva120 Stacks of Flapjacks 翻煎饼
- 解题报告 之 UVA120 Stacks of Flapjacks
- [UVA120]Stacks of Flapjacks[STL][构造]
- 煎饼(Stacks of Flapjacks,UVA120)
- Uva120——Stacks of Flapjacks
- UVA120:Stacks of Flapjacks(煎饼)
- Stacks of Flapjacks 翻煎饼-UVA120 白书第五章
- [高效算法 deque运用]UVa120 - Stacks of Flapjacks
- Uva120 Stacks of Flapjacks【构造法】【例题8-1】
- UVa120 例题 8-1 煎饼 (Stacks of Flapjacks)
- 获得员工部门
- Android面试篇之HashMap和Hashtable的区别
- 查看某个端口的占用情况
- Essential Qt 第十八章 贪吃蛇(下)
- Python __init__.py 作用详解
- 【UVa120】Stacks of Flapjacks 模拟
- 深入理解WeakHashmap-转载
- 数据结构第五周项目-数制转换(栈)
- Stacked Conditional Generative Adversarial Networks for Jointly Learning Shadow Detection and Shadow
- HbaseTemplate进阶:利用hbase.properties文件对Hbase的集群和端口进行配置
- [leetcode] 27. Remove Element
- 《android多媒体api》之摄像头camera采集原始视频数据
- 机器学习实战 LR
- hadoop3.0新特性