UVa 120 Stacks of Flapjacks
来源:互联网 发布:东莞广电网络官网 编辑:程序博客网 时间:2024/05/16 15:03
Description
一个stack
每次可以把最上面的N个逆序
输出的是从下往上数的值
eg
总共有5个
5个全部逆序
输出1
上面4个逆序输出2
最后要把stack变成升序
问操作方法
Algorithm
书上有
从大往小
如果位置对 不管
不然就先放到最高 再放到正确位置
知道这个操作方法之后 就变成模拟题了
Hint
注意输出
Code
import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String string = scanner.nextLine(); Scanner scanner1 = new Scanner(string); ArrayList arrayList = new ArrayList(); while (scanner1.hasNextInt()) { arrayList.add(scanner1.nextInt()); } ArrayList arrayList1 = new ArrayList(arrayList); int size = arrayList.size(); arrayList1.sort(((o1, o2) -> { if ((int)o1 < (int)o2) return 1; else return -1; })); System.out.print(arrayList.get(0)); for (int i = 1; i < arrayList.size(); i++) { System.out.printf(" %d", arrayList.get(i)); } System.out.print('\n'); for (int i = 0; i < size; i++) { if (arrayList1.get(i) != arrayList.get(size - i - 1)) { if (arrayList1.get(i) == arrayList.get(0)) { System.out.printf("%d ", i + 1); Collections.reverse(arrayList.subList(0, size - i)); }else { int x = arrayList.indexOf(arrayList1.get(i)); System.out.printf("%d ", size - x); Collections.reverse(arrayList.subList(0, x + 1)); if (arrayList1.get(i) != arrayList.get(size - i - 1)) { System.out.printf("%d ", i + 1); Collections.reverse(arrayList.subList(0, size - i)); } } } } System.out.println("0"); } }}
0 0
- UVA 120 Stacks of Flapjacks
- UVa 120 - Stacks of Flapjacks
- uva 120 Stacks of Flapjacks
- UVA 120 - Stacks of Flapjacks
- uva 120 - Stacks of Flapjacks
- UVa 120 - Stacks of Flapjacks
- UVA 120 - Stacks of Flapjacks
- UVa 120 - Stacks of Flapjacks
- UVA 120Stacks of Flapjacks
- UVA 120 - Stacks of Flapjacks
- uva 120 Stacks of Flapjacks
- UVA 120 Stacks of Flapjacks
- uva 120 Stacks of Flapjacks
- uva - 120 - Stacks of Flapjacks
- UVa 120 - Stacks of Flapjacks
- UVA - 120 - Stacks of Flapjacks
- UVa:120 - Stacks of Flapjacks
- UVa 120 - Stacks of Flapjacks
- Codeforces 667C Reberland Linguistics【DFS】
- 安卓java.lang.IllegalStateException: The specified child already has a parent.解决方案
- 《Vehicle Detection in High-Resolution Aerial Images Based on Fast Sparse Representation ...》论文笔记
- Android图片压缩方法总结
- Java中Filter、Servlet、Listener的学习
- UVa 120 Stacks of Flapjacks
- BZOJ 3670 [Noi2014]动物园
- 使用keepalive+lvs要注意的问题
- 超级简单的Android Studio jni 实现(无需命令行)
- 数据库设计三大范式
- Session的生命周期
- numpy的100个练习(一)
- javaScript学习笔记——如何在加载完某个标签之后执行一个函数
- 安卓活动的启动方式