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 ( ...
随机推荐
- centos7安装java开发环境
一. 安装jdk 1.进入oracle官网下载jdk-8u152-linux-x64.tar.gz,用WinScp将文件上传到/usr/local文件下 2.解压:执行命令 tar –xzvf jdk ...
- 简单的maven项目
手动建立一个简单的maven项目,不使用eclipse 好吧,第一步:建立一个项目路径,比如在d盘新建一个mavenTest文件夹,在mavenTest文件夹中建立HelloMaven的文件夹,作为项 ...
- flask-login2的简单使用
#coding:utf8 from flask import Flask, render_template, request, redirect, url_for, flash, abort from ...
- java 阿里云接口实现发送短信验证码
此刻自己做的小项目中,需要用到手机发送短信验证码实现注册功能,于是就去阿里云注册了账号,并实现随机发送验证码的功能 第一步:在阿里云官网登录注册 已有支付宝或淘宝的账号可以直接登录,最后需要实名认 ...
- Django 常用字段和参数
一.ORM字段 类型 说明 AutoField 一个自动增加的整数类型字段.通常你不需要自己编写它,Django会自动帮你添加字段:`id = models.AutoField(primary_key ...
- COGS2259 异化多肽
传送门 听说是多项式求逆的模板题,以后不怕没地方练多项式求逆啦哈哈…… …… 我们设使用一个氨基酸能组成质量为$n$的多肽数量这个数列为$\{a_n\}$,设它的生成函数为$A(x)$,显然有 \be ...
- SSRS 2008R2 执行Log 查询
1. 可以参考ExecutionLog3试图,此为系统安装Reporting Service自带的试图. 2. 可以使用以下语句查询: SELECT els.LogEntryId, els.Insta ...
- Qt 资料大全
https://blog.csdn.net/liang19890820/article/details/51752029 简述 发福利了.发福利了.发福利了,重要的事情说三遍... 为了方便更多Qte ...
- 深入理解并发编程之----synchronized实现原理
版权声明:本文为博主原创文章,请尊重原创,未经博主允许禁止转载,保留追究权 https://blog.csdn.net/javazejian/article/details/72828483 [版权申 ...
- 关于NativeEvent的处理
nativeEvent(const QByteArray &eventType, void *message, long *result){ chASSERT(message != NULL) ...