Sample Input
6 4 //输出第4个全排列
11 8

Sample Output
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10

 # include <cstdio>
# include <iostream>
# include <algorithm>
using namespace std ; int a[] ; int main ()
{
int n , m ;
while (scanf("%d %d" , &n , &m) != EOF)
{
int i ;
for (i = ; i <= n ;i++)
a[i] = i ;
int num = ;
while (num < m)
{
next_permutation(a+ , a++n) ;
num++ ;
}
for (i = ; i <= n- ;i++)
printf("%d " , a[i]) ;
printf("%d\n",a[n]) ;
}
}

hdu 1027 输出第m个全排列(next_permutation)的更多相关文章

  1. 关于全排列 next_permutation() 函数的用法

    这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...

  2. HDU 6351.Beautiful Now-暴力、全排列、思维 (2018 Multi-University Training Contest 5 1002)

    2018 Multi-University Training Contest 5 6351.Beautiful Now 题意就是交换任意两个数字,问你交换k次之后的最小值和最大值. 官方题解: 哇塞, ...

  3. 全排列next_permutation()用法和构造函数赋值

    全排列next_permutation()用法 在头文件aglorithm里 就是1~n数组的现在的字典序到最大的字典序的依次增加.(最多可以是n!种情况) int a[n]; do{ }while( ...

  4. HDU 1027 Ignatius and the Princess II[DFS/全排列函数next_permutation]

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  5. HDU 1027 Ignatius and the Princess II(求第m个全排列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/10 ...

  6. (全排列)Ignatius and the Princess II -- HDU -- 1027

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/100 ...

  7. HDU - 1027 Ignatius and the Princess II 全排列

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ( ...

  8. hdu 1027 Ignatius and the Princess II(产生第m大的排列,next_permutation函数)

    题意:产生第m大的排列 思路:使用 next_permutation函数(头文件algorithm) #include<iostream> #include<stdio.h> ...

  9. HDU 1716:排列2(全排列)

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

随机推荐

  1. HTML语义化

    什么是HTML语义化呢? 根据内容的结构化(内容语义化),选择合适的标签(代码语义化),便于开发者阅读,写出优雅的代码的同时让浏览器的爬虫更好的解析 语义化标签的优势: 1)代码结构清晰,方便阅读 2 ...

  2. 第k个素数

    题目描述 Output the k-th prime number. 输入描述: k≤10000 输出描述: The k-th prime number. #include <iostream& ...

  3. Linux下删除命令 硬盘空间查看... 常用命令

    (此命令请慎重使用) 使用rm -rf命令即可. 使用rm -rf 目录名字 命令即可 -r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思    (警告:不作任何 ...

  4. JS在Html中使用JavaScript

    一.三种方式 1)<script>元素 2)外部文件 3)文档模式 二.<script>元素 是向HTML页面插入JavaScript的主要方法:HTML 4.01为<s ...

  5. leetCode- 472. Concatenated Words

    因为每个组合的字符串,至少要有3个index. 起点,中间拼接点,结点.所以可以将字符串分解为子字符串,判断子字符串是否存在.但是,后面字符串的存在必须要在前面字符串已经存在基础上判断. class ...

  6. myeclispe 一直运行debug问题

    window->preferences->Myeclipse->Servers->Tomcat 然后找到你的相应的Tomcat服务器的版本,选中然后展开其下面的子菜单会发现有个 ...

  7. python 退出程序的方式

    python程序退出方式[sys.exit() os._exit() os.kill() os.popen(...)] 知乎说明 http://www.zhihu.com/question/21187 ...

  8. UART中的硬件流控RTS与CTS DTR DSR DTE设备和DCE设备【转】

    中低端路由器上使用disp interface 查看相应串口状态信息,其中DCD.DTR.DSR.RTS及CTS等五个状态指示分别代表什么意思? DCD ( Data Carrier Detect 数 ...

  9. gitlab代码仓库迁移

    有的时候我们需要对gitlab上的代码进行迁移,希望在迁移后能保持原有的branch.tag.commit记录等.可以使用以下方式: 1.clone代码到本地. 2.修改remote仓库的地址,添加新 ...

  10. Android命令Monkey压力测试,详解

    一.Monkey 是什么?Monkey 就是SDK中附带的一个工具. 二.Monkey 测试的目的?:该工具用于进行压力测试. 然后开发人员结合monkey 打印的日志 和系统打印的日志,结局测试中出 ...