POJ 2275 Flipping Pancake
题意 : 按我自己的理解就是,给你n个数,按照从上到下排列,现在让你进行一系列的操作,让你将数按照从大到小排好。
思路 : 比赛的时候以为要用记录路径的搜索,当时没什么把握,所以没做,今天网上一搜,我觉得这位神说的很对啊(链接),最简单的就是你从最大的开始换啊。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm> using namespace std ; int a[],b[] ; int main()
{
int n ;
int c[] ;
while(~scanf("%d",&n))
{
if(n == )
break ;
for(int i = ; i < n ; i++)
{
scanf("%d",&a[i]) ;
b[i] = a[i] ;
}
memset(c,,sizeof(c)) ;
int cnt = ;
sort(b,b+n) ;
// reverse(b,b+n) ;
for(int i = n- ; i > ; i--)
{
if(a[i] != b[i])
{
for(int j = ; j < i ; j++)
{
if(b[i] == a[j])
{
if(j != )
{
c[cnt++] = j+ ;
reverse(&a[],&a[j+]) ;
}
c[cnt++] = i+ ;
reverse(&a[],&a[i+]) ;
break ;
}
}
}
}
printf("%d ",cnt) ;
for(int i = ; i < cnt ; i ++)
printf("%d ",c[i]) ;
printf("\n") ;
}
return ;
}
POJ 2275 Flipping Pancake的更多相关文章
- 九度OJ 1146:Flipping Pancake(翻饼子) (递归、游戏)
时间限制:1 秒 内存限制:32 兆 特殊判题:是 提交:265 解决:116 题目描述: We start with a stack n of pancakes of distinct sizes. ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
- POJ 3185 The Water Bowls 【一维开关问题 高斯消元】
任意门:http://poj.org/problem?id=3185 The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
随机推荐
- SwithAndActivity 选择开关和活动指示
//// ViewController.m// SwithAndActivity//// Created by qianfeng on 15/9/21.// Copyright (c) 201 ...
- ASP.NET实现折线图的绘制
用到.Net中绘图类,实现折线图的绘制,生成图片,在页面的显示,代码如下: /// <summary> /// 获取数据 /// strChartName:图名称: /// yName:纵 ...
- 慕课网上的Bootstrap学习(二)
表单 首先<form role="form" class="form-horizontal"></form> ,创建一个水平显示的表单. ...
- UVALive 2889(回文数字)
题意:给定i,输出第i个回文数字. 分析:1,2,3,4,……,9------------------------------------------------------------------- ...
- Linux 简单字符设备驱动程序 (自顶向下)
第零章:扯扯淡 特此总结一下写的一个简单字符设备驱动程序的过程,我要强调一下“自顶向下”这个介绍方法,因为我觉得这样更容易让没有接触过设备驱动程序的童鞋更容易理解,“自顶向下”最初从<计算机网络 ...
- nginx gzip filter模块分析
API:http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/zlib-deflateinit2.html ...
- [Linux]学习笔记(1)
说到Linux就不得不提UNIX,因为Linux是从UNIX系统发展来的,两系统极为相似,可以在UNIX操作系统上使用的功能都可以在Linux上使用,只可能有少许的差异: UNIX系统中所有的东西都是 ...
- Ubuntu安装google Gtest
(1) 下载源码:http://code.google.com/p/googletest/gtest-1.7.0 (2013)gtest-1.7.0 (2010) (2) README编译指南126 ...
- 使用泛型 类型“System.Collections.Generic.IEnumerator<T>”需要 1 个类型参数
解决办法:添加 using System.Collections:命名空间
- mybatis + postgresql 遇到的问题
org.postgresql.util.PSQLException: ERROR: relation "circlefence" does not exist 这个问题是数据库表 ...