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/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10388 Accepted Submission(s): 5978
"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?
11 8
1 2 3 4 5 6 7 9 8 11 10
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
int a[n];
int k=;
for(int i=;i<n;i++)
{
a[i]=i+;
}
while(next_permutation(a,a+n))//调用依次此函数就是把这个序列变成下一个序列
{
k++;
if(k==m)
break;
}
printf("%d",a[]);
for(int i=;i<n;i++)
{
printf(" %d",a[i]);
}
printf("\n");
}
return ;
}
HDU 1027 Ignatius and the Princess II(求第m个全排列)的更多相关文章
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- HDU - 1027 Ignatius and the Princess II 全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- 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 ( ...
- hdu 1027 Ignatius and the Princess II(正、逆康托)
题意: 给N和M. 输出1,2,...,N的第M大全排列. 思路: 将M逆康托,求出a1,a2,...aN. 看代码. 代码: int const MAXM=10000; int fac[15]; i ...
- HDU 1027 Ignatius and the Princess II 选择序列题解
直接选择序列的方法解本题,可是最坏时间效率是O(n*n),故此不能达到0MS. 使用删除优化,那么就能够达到0MS了. 删除优化就是当须要删除数组中的元素为第一个元素的时候,那么就直接移动数组的头指针 ...
- HDU 1027 - Ignatius and the Princess II
第 m 大的 n 个数全排列 DFS可过 #include <iostream> using namespace std; int n,m; ]; bool flag; ]; void d ...
- HDU 1027 Ignatius and the Princess II 排列生成
解题报告:1-n这n个数,有n!中不同的排列,将这n!个数列按照字典序排序,输出第m个数列. 第一次TLE了,没注意到题目上的n和m的范围,n的范围是小于1000的,然后m的范围是小于10000的,很 ...
- hdu 1027 Ignatius and the Princess II(产生第m大的排列,next_permutation函数)
题意:产生第m大的排列 思路:使用 next_permutation函数(头文件algorithm) #include<iostream> #include<stdio.h> ...
- poj 1027 Ignatius and the Princess II全排列
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
随机推荐
- PL/SQL 快速连接数据库
打开PL/SQL 登录窗口,在数据库地址写入 服务器名:端口号/sid 即可, 例如: 192.168.100.100:1521/test
- 浅谈jquery中prop()和attr()
我们都知道,一般在jquery中设置属性时要用到attr()方法,现在我们有一个效果,点击按钮切换复选框的选中状态,下面贴出html代码: <input type="checkbox& ...
- SPOJ:COT2 Count on a tree II
题意 给定一个n个节点的树,每个节点表示一个整数,问u到v的路径上有多少个不同的整数. n=40000,m=100000 Sol 树上莫队模板题 # include <bits/stdc++.h ...
- mac下打开hosts文件
1打开控制台 输入vi(空格)/etc/hosts 进入hosts文件,输入i更改为编辑状态,更改完esc然后shift+:在输入wq保存退出 2打开Finder然后选择上面前往,到前往文件夹,输入/ ...
- 初学者需要IPython 与 Jupyter Notebook 吗?
ipython 是 jupyter notebook的前身并拥有ipython的全部功能 jupyter拥有 cell, markdown 整合的功能, 能同时运行代码, 而且是多组的 ...
- Common in Hardware & Software
A lot of common in Hardware programming & Software Programming
- RoadFlowCore工作流2.8.1 更新日志
1.2.8.1更新了2.8刚发布的一些小BUG. 2.2.8.1增加了移动端,基于微信企业号或企业微信. 详细请参阅官方网站:roadflow.net
- 任务十五:零基础JavaScript编码(三)
任务目的 在上一任务基础上继续JavaScript的体验 接触一下JavaScript中的高级选择器 学习JavaScript中的数组对象遍历.读写.排序等操作 学习简单的字符串处理操作 任务描述 参 ...
- ado.net c#基本的增加,修改,删除,查询
自己初次学习用的,各种不规范,注释没写 class AdoDemo { static string strConn = @"Data Source=server1;Initial Catal ...
- java面试题之----Java内部类
这是我学习Java内部类的笔记 1.为什么使用内部类? 使用内部类最吸引人的原因是:每个内部类都能独立地继承一个(接口的)实现,所以无论外围类是否已经继承了某个(接口的)实现, 对于内部类都没有影响 ...