应该也是模拟_题目1146:Flipping Pancake
来源:互联网 发布:linux下oracle创建实例 编辑:程序博客网 时间:2024/05/17 04:50
题目给的测试数据能过,但一提交却变成RA
貌似问题是出在第28行和第31行,因为我一注释掉它们就变成WA
可能是在特定的输入下它们会导致下标越界之类的错误,但就是想不通究竟是啥情况,SOS~
这道题原本没那么多提交的,全是给我的RA刷的 T_T
时间限制:1 秒
内存限制:32 兆
特殊判题:是
提交:110
解决:41
- 题目描述:
We start with a stack n of pancakes of distinct sizes. The problem is to convert the stack to one in which the pancakes are in size order with the smallest on the top and the largest on the bottom. To do this, we are allowed to flip the top k pancakes over as a unit (so the k-th pancake is now on top and the pancake previously on top is now in the k-th position).
For example: This problem is to write a program, which finds a sequence of at most (2n - 3) flips, which converts a given stack of pancakes to a sorted stack.
- 输入:
Each line of the input gives a separate data set as a sequence of numbers separated by spaces. The first number on each line gives the number, N, of pancakes in the data set. The input ends when N is 0 (zero) with no other data on the line. The remainder of the data set are the numbers 1 through N in some order giving the initial pancake stack.
The numbers indicate the relative sizes of the pancakes. N will be, at most, 30.
- 输出:
For each data set, the output is a single-space separated sequence of numbers on a line. The first number on each line, K, gives the number of flips required to sort the pancakes. This number is followed by a sequence of K numbers, each of which gives the number of pancakes to flip on the corresponding sorting step. There may be several correct solutions for some datasets. For instance 3 3 2 3 is also a solution to the first problem below.
- 样例输入:
3 1 3 25 4 3 2 5 10
- 样例输出:
3 2 3 2 3 3 4 5
- 来源:
- 2009年北京大学计算机研究生机试真题
- 答疑:
- 解题遇到问题?分享解题心得?讨论本题请访问:http://t.jobdu.com/thread-7869-1-1.html
可怜的被创造出来却没法运行的代码的清单 T_T
#include <stdio.h>#define MAX 100 int e[MAX];int ans[2*MAX] = {0};int n;void reverse(int i){ if(i>0) ans[++ans[0]] = i+1; int temp; int j=0; while(i > j){ temp = e[i]; e[i--] = e[j]; e[j++] = temp;}} int main(){ while(scanf("%d",&n),n){ for(int i=0; i<n; i++) scanf("%d",e+i); for(int i=1; i<n; i++){ if(e[i] > e[i-1]) continue; if(e[i] < e[0]){ reverse(i-1); reverse(i);} else{ reverse(i); int j=0; while(j<n-1 && e[j+1] > e[0]) j++; reverse(j); reverse(i); i = i-j+1;}} for(int i=0;i<=ans[0];i++){ printf("%d ",ans[i]);} printf("\n"); ans[0]=0;} return 0;}/************************************************************** Problem: 1146 User: denallo Language: C Result: Runtime Error****************************************************************/
- 应该也是模拟_题目1146:Flipping Pancake
- 题目1146:Flipping Pancake
- 题目1146:Flipping Pancake
- 九度OJ;题目1146:Flipping Pancake
- OJ_1146 Flipping Pancake
- 九度OJ 1146:Flipping Pancake(翻饼子) (递归、游戏)
- Flipping Burned Pancakes --模拟
- 模拟_题目1079:手机键盘
- 模拟_题目1145:Candy Sharing Game
- HDU 1988 Flipping Burned Pancakes (模拟)
- 语言入门-题目33(蛇形矩阵)_模拟
- 由一些公司的笔试题目想到的---模拟电路,数字电路最基本应该知道哪些
- 现在使用应该也是不晚的
- HDU 1988 & ZOJ 2991 Flipping Burned Pancakes(数学啊+模拟)
- Flipping colors
- Flipping Game
- Flipping Parentheses
- Flipping Game
- 百度推荐与个性化部-架构组二面
- 短信平台PHP代码实现
- 如何弹出QQ临时对话框,实现不添加好友的在线交谈效果。
- js正则解析URL参数
- C++ hash_map 与 Java HashMap 的区别
- 应该也是模拟_题目1146:Flipping Pancake
- F5调试F11无法进入DLL动态库里面LIB静态库方法
- 第七周项目4:复数模板类
- Eclipse @override报错解决
- HDU4542-小明系列故事——未知剩余系(数论)
- 设计模式之四:外观模式(Facade Pattern)
- 显示原理理解 DEVMODE理解
- this和super的用法
- python 编码问题