Java hdoj 1027 Ignatius and the Princess II
来源:互联网 发布:淘宝运营培训费用 编辑:程序博客网 时间:2024/04/28 00:47
import java.util.*;public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);while (in.hasNext()) {int N = in.nextInt();int M = in.nextInt();int[] a = new int[N];for (int i = 0; i < a.length; i++) a[i] = i + 1;for (int i = 1; i < M; i++)nextPermutation(a);System.out.print(a[0]);for (int i = 1; i < a.length; i++)System.out.print(" " + a[i]);System.out.println();}}public static void nextPermutation(int[] a) {int llr = 0;for (int i = a.length - 1; i > 0; i--)if (a[i - 1] < a[i]) {llr = i - 1;break;}int min = llr + 1;for (int i = llr + 1; i < a.length; i++)if (a[i] > a[llr] && a[i] < a[min])min = i;swap(llr, min, a);reserve(llr + 1, a);}public static void swap(int i, int j, int[] a) {int temp = a[i];a[i] = a[j];a[j] = temp;}public static void reserve(int i, int[] a) {for (int j = i, k = 0; j < (i + a.length) / 2; j++, k++) swap(j, a.length - 1 - k, a);}}
0 0
- HDOJ 1027 Ignatius and the Princess II
- HDOJ 1027 Ignatius and the Princess II
- HDOJ 1027 Ignatius and the Princess II
- hdoj 1027 Ignatius and the Princess II
- hdoj 1027 Ignatius and the Princess II
- HDOJ 1027 Ignatius and the Princess II
- hdoj 1027 Ignatius and the Princess II
- Java hdoj 1027 Ignatius and the Princess II
- hdoj 1027 Ignatius and the Princess II 【逆康托展开】
- HDOJ 题目1027 Ignatius and the Princess II(STL)
- HDOJ 1027 Ignatius and the Princess II - next_permutation函数
- hdoj 1027 Ignatius and the Princess II 【基础】
- HDOJ 1027Ignatius and the Princess II(全排列)
- HDOJ 1027-Ignatius and the Princess II【全排列】
- hdoj--1027--Ignatius and the Princess II(dfs)
- hdoj 1027 Ignatius and the Princess II(全排列变形)
- hdoj 1027 Ignatius and the Princess II 【全排列】【STL】
- hdoj 1027 Ignatius and the Princess II(排列组合)
- 学习C++一些必读经典书籍
- we玩儿玩儿
- 批处理递归删除指定后缀的文件
- 字符串处理--HDU第1020题解题报告
- iOS 点击屏幕任意空白处,键盘消失
- Java hdoj 1027 Ignatius and the Princess II
- IOS开发——IOS7 状态栏颜色更改
- p2p
- 黑马程序员学习笔记——单例设计模式
- notepad++插件使用技巧
- 堆排序
- 一次且仅一次(once and only once,简称OAOO)
- 9招教你如何设计一款电商app,并实现使用量170%增长
- java设计模式(结构型)之适配器模式