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) ...
随机推荐
- 0121 spring-boot-redis的使用
redis是什么呢?redis,属于NoSQL的一种,在互联网时代,起到加速系统的作用. redis是一种内存数据库,支持7种数据类型的存储,性能1S 10w次读写: redis提供的简单的事务保证了 ...
- 函数match应打印s中从ch1到ch2之间的所有字符,并且返回ch1的地址。
1 char *match( char *s, char ch1, char ch2 ){ ; ; ; while(s[len]){ len++; } *len+];//防止s字符串全满导致t溢出 * ...
- 大数据-sparkSQL
SparkSQL采用Spark on Hive模式,hive只负责数据存储,Spark负责对sql命令解析执行. SparkSQL基于Dataset实现,Dataset是一个分布式数据容器,Datas ...
- Jquery拖拽,拖动排序插件
上github搜jquery-sortable <!-- jq拖拽排序 --> <script src="${contextPath}/static/excelTable/ ...
- Oracle存储过程----存储过程执行简单的增删改查
1.存储过程执行增加的sql create or replace procedure test_add(id varchar,name varchar,time varchar,age varchar ...
- selenium参数化-ddt模块
DDT介绍: DDT(数据驱动测试)允许您通过使用不同的测试数据运行一个测试用例来使其倍增,并使它显示为多个测试用例.要使用DDT需要安装,安装命令:pip install ddt 使用方法: dd. ...
- Jarvis OJ - Baby's Crack - Writeup
Jarvis OJ - Baby's Crack - Writeup M4x原创,欢迎转载,转载请表明出处 这是我第一次用爆破的方法做reverse,值得记录一下 题目: 文件下载 分析: 下载后解压 ...
- node.js 和 yarn 安装
电脑环境 windows10 专业版 64 位 node.js 安装 Node.js 官方网站下载:https://nodejs.org/en/ 之后一步步得傻瓜式安装 配置环境变量和查看node.j ...
- 395. 至少有K个重复字符的最长子串
Q: A: 分治,对于字符串s的任何一个字符,如果它的频数(在s中出现的次数)小于k,则它一定不会出现在最后的结果里,也就是从它的位置一劈两半,考察左右.对于当前字符串s,我们先建立字典统计其中每种字 ...
- [vue学习]快速搭建一个项目
安装node.js 官网:https://nodejs.org/en/ 淘宝NPM镜像(npm是外网,用国内代理下载安装贼快) $ npm install -g cnpm --registry=htt ...