这个题没什么算法,就是想出怎么把答案构造出来就行。

思路:越大的越放在底端,那么每次就找出还没搞定的最大的,把它移到当前还没定好的那些位置的最底端,定好的就不用管了。

这道题要处理好输入,每次输入的一行中是带空格的,以换行符结束一组数据的输入,那么用getline()函数。再用stringstream(这个可以自动转格式),非常方便的就处理了输入的问题。另外注意max_element和min_element都是左闭右开的。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define INF 1000000000
#define eps 1e-8
#define pii pair<int,int>
#define LL long long int
#define maxn 100010
int a[],n;
string s;
void flip(int p)
{
for(int i=;i<p-i;i++)//这里循环结束条件的设定有韵味
{
swap(a[i],a[p-i]);
}
printf("%d ",n-p);
}
int main()
{
//freopen("in8.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(getline(cin,s))
{
cout<<s<<endl;
stringstream ss(s);
n=;
while(ss>>a[n]) n++;
for(int i=n-;i>=;i--)
{
int p=max_element(a,a+i+)-a;
if(p==i) continue;
else if(p>) flip(p);
flip(i);
}
cout<<''<<endl;
}
//fclose(stdin);
//fclose(stdout);
return ;
}

uva120 Stacks of Flapjacks (构造法)的更多相关文章

  1. (白书训练计划)UVa 120 Stacks of Flapjacks(构造法)

    题目地址:UVa 120 水题. 从最大的開始移,每次都把大的先翻到最上面,再翻到以下. 代码例如以下: #include <iostream> #include <cstdio&g ...

  2. UVa120 - Stacks of Flapjacks

    Time limit: 3.000 seconds限时:3.000秒 Background背景 Stacks and Queues are often considered the bread and ...

  3. Uva120 Stacks of Flapjacks 翻煎饼

    水水题.给出煎饼数列, 一次只能让第一个到第i个数列全部反转,要求把数列排序为升序. 算法点破后不值几钱... 只要想办法把最大的煎饼放到最后一个,然后就变成前面那些煎饼的数列的子题目了.递归或循环即 ...

  4. 【思维】Stacks of Flapjacks

    [UVa120] Stacks of Flapjacks 算法入门经典第8章8-1 (P236) 题目大意:有一个序列,可以翻转[1,k],构造一种方案使得序列升序排列. 试题分析:从插入排序即可找到 ...

  5. Uva 120 - Stacks of Flapjacks(构造法)

    UVA - 120  Stacks of Flapjacks Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld &a ...

  6. uva 120 stacks of flapjacks ——yhx

     Stacks of Flapjacks  Background Stacks and Queues are often considered the bread and butter of data ...

  7. UVaOJ 120 - Stacks of Flapjacks

    120 - Stacks of Flapjacks 题目看了半天......英语啊!!! 好久没做题...循环输入数字都搞了半天...罪过啊!!! 还是C方便一点...其实C++应该更方便的...C+ ...

  8. uva Stacks of Flapjacks

                                                     Stacks of Flapjacks  题目链接:Click Here~ 题目描写叙述:     ...

  9. 利用子集构造法实现NFA到DFA的转换

    概述 NFA非有穷自动机,即当前状态识别某个转换条件后到达的后继状态不唯一,这种自动机不便机械实现,而DFA是确定有限状态的自动机,它的状态转换的条件是确定的,且状态数目往往少于NFA,所以DFA能够 ...

随机推荐

  1. iOS Application Project与OS X Application Project对于plist使用的区别

    前几天因为在开源中国看到一个求源代码的问题: 模拟一个动物园系统MyZoo 1.动物园里面有三种动物:Panda,Elephant,Kangaroo 2.三种动物都有一定的数量(不止一只) 3.动物有 ...

  2. notepad++运行python代码

    notepad++运行代码 在菜单栏中点击运行或按F5,在弹出的对话框中输入下面命令 cmd /k E:\py3.6\python.exe "$(FULL_CURRENT_PATH)&quo ...

  3. This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in问题

    点击 Help > Install New Software. 在 Work with 的输入区域里, 输入: https://dl-ssl.google.com/android/eclipse ...

  4. requirejs源码分析: 路径

    1. 没有设置baseUrl(一般我们都会设置baseurl)        在没有设置baseUrl时, 默认  baseurl: "./"        当指定data-mai ...

  5. 20160422 --Switch…case 总结; 递归算法

    13 2016-04-22  11:01:00 Switch…case 总结(网摘) 例题: Console.WriteLine("1.汉堡包"); Console.WriteLi ...

  6. <script>放在head内和body内有什么区别

    加载的顺序不一样,你可以把HTML看成从上往下加载的. 例如在网速慢的情况下把js代码放在body底部用户会先看到网页结构,等js加载完成后才出现特效 区别简述: 在HTML body部分中的Java ...

  7. collectionView的案例

    #import "ViewController.h" #import "CollectionViewCell.h" @interface ViewControl ...

  8. React-Native Listview组件用法详解

    ListView作为React Native的核心组件,用于高效地显示一个可以垂直滚动的变化的数据列表.其中最重要的属性之一是DataSource,列表依赖的数据源,用于实例化一个ListView对象 ...

  9. create_workqueue和create_singlethread_workqueue【转】

    本文转载自:http://bgutech.blog.163.com/blog/static/18261124320116181119889/ 1. 什么是workqueueLinux中的Workque ...

  10. WebLogic 12c 多节点Cluster静默安装

    WebLogic集群架构 Weblogic角色 AdminServer: 172.16.65.130 NodeServer: 172.16.65.131.172.16.65.132 版本 weblog ...