HDU1027 Ignatius and the Princess II
"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 <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime> using namespace std; int a[]; int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<n;i++)
a[i]=i+; int cnt=; do
{
cnt++;
if(cnt==m)
break; }while(next_permutation(a,a+n));
//next_permutation(first,last)按字典序升序全排列,prev_permutation(first,last)按字典序降序全排列 for(i=;i<n;i++)
{
printf("%d",a[i]);
if(i!=n-)
printf(" ");
}
printf("\n");
}
return ;
}
HDU1027 Ignatius and the Princess II的更多相关文章
- 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 ( ...
- hdu1027 Ignatius and the Princess II (全排列 & STL中的神器)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1027 Ignatiu ...
- HDU1027 Ignatius and the Princess II( 逆康托展开 )
链接:传送门 题意:给出一个 n ,求 1 - n 全排列的第 m 个排列情况 思路:经典逆康托展开,需要注意的时要在原来逆康托展开的模板上改动一些地方. 分析:已知 1 <= M <= ...
- ACM-简单题之Ignatius and the Princess II——hdu1027
转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...
- ACM-简单的主题Ignatius and the Princess II——hdu1027
转载请注明出处:http://blog.csdn.net/lttree Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Othe ...
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- Ignatius and the Princess II(全排列)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
- Ignatius and the Princess II
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- (next_permutation)Ignatius and the Princess II hdu102
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
随机推荐
- [转] .NET领域驱动设计—初尝(原则、工具、过程、框架)
阅读目录: 1.原则 1.1.精简聚合 1.2.分离用例与接口功能(设计模式的用武之地) 2.工具.框架.组件 3.过程 1]原则 原则对于任何一项技术实现来说都是至关重要的,在设计某一个系统功能的时 ...
- MVC启动windows身份验证时初次访问特别慢
最近做了一个关于MVC的项目,刚开始往服务器上面部署时,没有开启windows身份验证,等开发基本收尾时候,将验证开启时,第一次打开的时候需要将近15s的访问时间,别说用户受不了,自己都受不了了. 对 ...
- AngularJS高级程序设计读书笔记 -- 指令篇 之 自定义指令
2. 自定义指令(15-17 章) Module.directive(name, factory) 2.1 创建自定义指令的方法 Module.directive(name, factory) 示例 ...
- Python3.5学习笔记-列表、元组、字典
Python中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建.在Python中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型 ...
- kindeditor使用入门-张国红
kindeditor是在线编辑器,比较好用,以下是使用这个插件的步骤. 下载kindeditor-4.1.10.zip 解压 asp,asp.net,php对于jsp开发没有用,可以删除 新建web工 ...
- Redis事务原理分析
Redis事务原理分析 基本应用 在Redis的事务里面,采用的是乐观锁,主要是为了提高性能,减少客户端的等待.由几个命令构成:WATCH, UNWATCH, MULTI, EXEC, DISCARD ...
- mongodb远程连接配置
mongodb远程连接配置如下: 1.修改配置文件mongodb.conf 命令:vim /etc/mongodb.conf 把 bind_ip=127.0.0.1 这一行注释掉或者是修改成 bind ...
- h1b期间回国须知
今天才搞明白几点 1. visa 和 status 是两个不同的东西,status能保证合法在美国.visa能保证合法进入美国 所以,h1b十月份的身份转换时status的转换,如果回国还需要重新办h ...
- 流行框架(angularj基础)
- 移动端300ms的点击延迟以及解决方案
[今天做在移动端的一些效果时,我选择使用动画而不是用过渡,这个300ms的点击延迟是我为什么使用动画而不使用过渡最主要的一个原因] 动画和过渡 共同点:都是css控制DOM运动, 不同点: 1.过渡: ...