uva 120——Stacks of Flapjacks
题意:一个非常有趣的问题,就是给一摞煎饼,然后从下面拿起来一张,然后把该张上面的所有馅饼反转,求最后使得馅饼从小到大的最小的步数。
思路:贪心。每次都把没排好序的最大数反转到最上面,然后在一次反转到最下面,也就是最多需要2n步就能够把所有的馅饼排好。
Code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <set>
using namespace std;typedef long long ll;
typedef unsigned long long ull;
const int N=1000000;
const int M=105;
const int mod=10000007;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-9;
const double pai=acos(-1.0);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define cls(x,c) memset(x,c,sizeof(x))
#define fr(i,n) for (int i=0;i<n;i++)int a[35],len;
int tran(int j)
{int t=j;for (int i=0;i<j;i++)if (a[i]>a[t]) t=i;return t;
}
int main()
{string s;int i,j;while (getline(cin,s)){if (s=="") break;cout<<s<<endl;stringstream ss;ss<<s;len=0;while (ss>>a[len]) len++;//fr (i,len) cout<<"bug2"<<a[i]<<endl;for (int i=len-1;i>=0;i--){j=tran(i);//cout<<"bug "<<j<<endl;if (j==i) continue;if (j!=0){printf("%d ",len-j);reverse(a,a+j+1);}reverse(a,a+i+1);printf("%d ",len-i);}puts("0");}
}
uva 120——Stacks of Flapjacks相关推荐
- UVa 120 - Stacks of Flapjacks
题意:给一摞随意摞的煎饼,要按直径从上到下递增的顺序排列,求翻的顺序. 思路:贪心. 1,读取煎饼数据,新建一个数组,复制数据,排序,作为参考. 2,从最大直径(maxNum)的煎饼开始,看其是否在底 ...
- Stacks of Flapjacks UVA 薄饼排序问题
// 有点类似栈和队列的操作,但在这里可以用纯数组模拟出来.#include <iostream>#include <cstring>#include <cstdio&g ...
- π-Algorithmist分类题目(3)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(3) Probability ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
- sicily题目分类
sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...
- [sicily]部分题目分类
sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...
- Sicily 题目分类
依照自己水平挑着做→ →~~ 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 ...
- 编程题目分类(剪辑)
1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代 ...
最新文章
- Android中Canvas绘图之Shader使用图文详解
- memcached使用详解
- 小红书最新用户量数据_小红书估值高达60亿美元?小红书超过蘑菇街了吗?
- python redis 操作_Python 使用 Redis 操作
- React Native工程修改Android包名
- mysql 5.5.37安装_MySQL5.5.37编译安装详解
- 关于电脑误删摸个配置文件导致系统异常的解决方法(知道误删的什么文件)
- 毫秒转换成对应到达时间
- Python爬虫实战案例讲解——爬虫爬取地铁线路图
- linux下部署项目,下载文件时,中文文件名乱码问题
- 惠普暗影精灵u盘启动linux,暗影精灵5 安装w10+ Ubuntu18.0.4
- 远程桌面启动安卓模拟器
- 查询时报错The error may involve defaultParameterMap ### The error occurred while setting parameters
- 智能照明控制系统助力某商业综合体实现“双碳”
- Python处理excel-根据全称自动填写简称
- STM32cubIDE 黑色主题_主题 | Mation 微信主题 适配7和7以下版本
- 中国电信吴湘东:云网一体化将为运营商带来新的融合和创新
- maching learning入门(二)
- RT1052 ENET ENET_SendFrame调用 未发送帧
- elasticsearch ik pingyin 分词器的安装和使用
热门文章
- 如何安装 Angular CLI 并且检查 CLI 的版本
- CentOS 7 Flannel的安装与配置
- How to fix the bug “Expected required, optional, or repeated.”?
- StringMVC 中如何做数据校验
- node--更新数据库问题
- (转)MOMO的Unity3D研究院之深入理解Unity脚本的执行顺序(六十二)
- mysql 帐号开启远程_两大步骤教您开启MySQL 数据库远程登陆帐号
- saas物资管理界面设计_大型物流企业都在用的SaaS系统,看大规模运配网络如何实现精细化管理?...
- java 读取ppt文件_java使用poi读取ppt文件和poi读取excel、word示例
- android webview sql database,websql在openDatabase报version mismatch错误,请问怎么解决?