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) ...
随机推荐
- 查看gcc编译器版本
我们在windows下DS5中编译时使用GCC交叉编译器,但是在ubuntu时也需要使用GCC编译器,这时最好时保持版本一致,所以就需要查看windows下版本,如下图,在按装的文件夹中找到对应得文件 ...
- 我竟然把today = new Date();写在了全局变量里面
let today = new Date();应该在每次用之前重新生成新的对象,因为对于例如 today.getTime() 这种方法,取得是today对象的time,而非调用today对象取得实时时 ...
- UI高级组件
今天继续学习UI高级组件 网格视图 GridView 用GridView标签添加,显示网格视图,需要用到适配器,共有四种适配器 ArrayAdapter,SmipleAdapter,SmipleCou ...
- AcWing 799. 最长连续不重复子序列 双指针(一般先写一个朴素暴力的做法,然后看两个指针直接是否存在单调关系,如果存在,就想方法优化)
https://www.acwing.com/problem/content/801/ #include<bits/stdc++.h> using namespace std ; int ...
- ❀❀ 名词解释(PM、PD、UE、UI、RD....)
PM:产品经理,项目负责人.一个产品,首先由PM来分析细分市场.目标客户的诉求,规划产品的卖点.杀手级应用,这个过程通常PD已经介入了,这个层面上,商业问题.业务逻辑的流畅是思考的焦点. 举凡产品从创 ...
- 每天进步一点点------ModelSim仿真Altera的ROM
1. 在QuartusII中生成rom的初始化文件,可以是hex,也可以是mif.MIF文件的格式很简单明了,所以我一向都是用MIF. 2.下载convert_hex2ver.dll文件,conver ...
- eclipse报错:unable to install breakpoint in .......due to missing line number attributes
报错信息如下: 解决方案方案1.把断点都干掉,再启动.应该是代码更新后,断点位置没有代码了或位置改变了. 方案2.在Eclipse - Preferences - Java - Complier 下 ...
- Yum与list结合
我用两台Linux LinuxA IP:192.168.10.101 LinuxB IP:192.168.10.102 首先我们在LinuxA上挂载光驱和安装FTP服务器 然后安装 ...
- Elasticsearch系列---shard内部原理
概要 本篇我们来看看shard内部的一些操作原理,了解一下人家是怎么玩的. 倒排索引 倒排索引的结构,是非常适合用来做搜索的,Elasticsearch会为索引的每个index为analyzed的字段 ...
- ubuntu刪除軟件
1.打开一个终端,输入dpkg --list ,按下Enter键,终端输出以下内容,显示的是你电脑上安装的所有软件2.在终端中找到你需要卸载的软件的名称,列表是按照首字母排序的.3.在终端上输入命令s ...