next_permutation的使用-Hdu1027
Ignatius and the Princess II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14475 Accepted Submission(s): 8296
"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
#include <bits/stdc++.h> using namespace std; int a[]; int main()
{
int n,m;
while(cin>>n>>m){
for(int i = ;i <= n; i++)
a[i] = i;
int b = ;
do{
if(b==m)
break;
b++;
}while(next_permutation(a+,a+n+));
for(int i = ;i < n; i++)
cout<<a[i]<<" ";
cout<<a[n]<<endl;
}
return ;
}
next_permutation的使用-Hdu1027的更多相关文章
- HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 关于全排列 next_permutation() 函数的用法
这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...
- About next_permutation
哈哈没错这个又是我们C++党的语言优势之一,用这个函数可以求当前排序的下一个排序,也就是说可以方便的求全排列,用这个函数需要用到algorithm这个头文件. 与这个函数相反的是prev_permut ...
- STL next_permutation和prev_permutation函数
利用next_permutation实现全排列升序输出,从尾到头找到第一个可以交换的位置, 直接求到第一个不按升序排列的序列. #include <iostream> #include & ...
- 【STL】next_permutation的原理和使用
1.碰到next_permutation(permutation:序列的意思) 今天在TC上碰到一道简单题(SRM531 - Division Two - Level One),是求给定数组不按升序排 ...
- (转)ACM next_permutation函数
转自 stven_king的博客 这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记 (1) int 类型的next_permuta ...
- next_permutation函数
这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm>下面是以前的笔记 与之完全相反的函数还有prev_permutation (1) int 类 ...
- buaaoj230——next_permutation的应用
题目地址 简单的全排列输出,借用stl中的next_permutation就非常简单了. 关于next_permutation:(备忘,来源网络) /*这是一个求一个排序的下一个排列的函数,可以遍历全 ...
- [算法]——全排列(Permutation)以及next_permutation
排列(Arrangement),简单讲是从N个不同元素中取出M个,按照一定顺序排成一列,通常用A(M,N)表示.当M=N时,称为全排列(Permutation).从数学角度讲,全排列的个数A(N,N) ...
随机推荐
- php核心技术与最佳实践--- oop
<?php /** * Created by PhpStorm. * User: cl * Date: 2019/8/12 * Time: 7:08 */ /*oop*/ class Perso ...
- .net_DevExpress控件使用经验总结
(转)DevExpress控件使用经验总结DevExpress是一个比较有名的界面控件套件,提供了一系列的界面控件套件的DotNet界面控件.本文主要介绍我在使用DevExpress控件过程中,遇到或 ...
- GIT如何根据历史记录回退代码
ps: 因为使用这种方式回退后,回退的目标版本之后提交的代码都没了,所以建议先把当前代码打个tag 首先找到分支的提交记录 git log 将代码回退到历史版本 git reset --hard 0f ...
- 第三十六篇 入门机器学习——Jupyter Notebook中的魔法命令
No.1.魔法命令的基本形式是:%命令 No.2.运行脚本文件的命令:%run %run 脚本文件的地址 %run C:\Users\Jie\Desktop\hello.py # 脚本一旦 ...
- Documents
centos 7 修改主机名 hostnamectl set-hostname myhostname ansible node -m raw -a "if [[ \$(cat /root/. ...
- Go网络编程UDP
package main import ( "fmt" "net" "strings" ) // UDP server func main( ...
- my97日期控件弹出位置显示异常
使用my97日期选择控件的时候,如果整个页面是有滚动条的,根据触发显示日期的控件的父控件的position不同会显示不同的情况 1.position不为fixed则滑动滚动条,显示的日期层不会出现异常 ...
- WIN10 设置WEB
Web服务器搭建步骤(Win10) 1.在“开始”菜单处打开“控制面板”. 2点击“程序”. 3.点击“启动或关闭Windows功能”. 4.对“Internet Information Servic ...
- Bugku-CTF分析篇-手机热点(有一天皓宝宝没了流量只好手机来共享,顺便又从手机发了点小秘密到电脑,你能找到它吗?)
手机热点 httppan.baidu.coms1cwwdVC 有一天皓宝宝没了流量只好手机来共享,顺便又从手机发了点小秘密到电脑,你能找到它吗? 题目来源:第七季极客大挑战
- 生成树计数 UVA 10766
//本题题意:首先每个点之间都可达,然后m列举出不可达的,求出最多的生成树方案: //k这个变量是没用的. //公式:ans矩阵=度矩阵-建边矩阵: //度矩阵是当i==j时的,建边矩阵于平时定义可达 ...