HDU——1027Ignatius and the Princess II(next_permutation函数)
Ignatius and the Princess II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6191 Accepted Submission(s): 3664
you can work them out, I will release the Princess, or you will be my dinner, too." Ignatius says confidently, "OK, at last, I will save the Princess."
"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?
file.
11 8
1 2 3 4 5 6 7 9 8 11 10
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
int n,m;
while(cin>>n>>m)
{
vector<int>list(n);
vector<int>::iterator it;
int k=1;
for (it=list.begin(); it!=list.end(); it++)
{
*it=k;
k++;
}
int COUNT=1;注意此题的 first sequence已经是题中所给的自然增长序列,无需计入
while (next_permutation(list.begin(),list.end()))
{
COUNT++;
if(COUNT==m)
break;
}
for (it=list.begin(); it!=list.end(); it++)
{
if(it!=list.end()-1)
cout<<*it<<' ';
else
cout<<*it<<endl;
}
}
return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
int n,m;
while(cin>>n>>m)
{
int *list=new int[n];
int i;
for (int i=0; i<n; i++)
{
list[i]=i+1;
}
int COUNT=1;注意此题的 first sequence已经是题中所给的自然增长序列,无需计入
while (next_permutation(list,list+n))
{
COUNT++;
if(COUNT==m)
break;
}
for (i=0; i<n; i++)
{
if(i!=n-1)
cout<<list[i]<<' ';
else
cout<<list[i]<<endl;
}
delete []list;
}
return 0;
}
HDU——1027Ignatius and the Princess II(next_permutation函数)的更多相关文章
- hdu Ignatius and the Princess II
Ignatius and the Princess II Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Ja ...
- 杭电1027Ignatius and the Princess II模拟
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1027 题目: Problem Description Now our hero finds the doo ...
- HDU Ignatius and the Princess II 全排列下第K大数
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include& ...
- 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(产生第m大的排列,next_permutation函数)
题意:产生第m大的排列 思路:使用 next_permutation函数(头文件algorithm) #include<iostream> #include<stdio.h> ...
- 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/10 ...
- 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 -- HDU -- 1027
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1027 Ignatius and the Princess II Time Limit: 2000/100 ...
- HDU 1027 Ignatius and the Princess II(康托逆展开)
Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ( ...
随机推荐
- WPF知识点全攻略11- 命令(Command)
先看一下命令的简单使用: <Window.CommandBindings> <CommandBinding Command="ApplicationCommands.Cut ...
- 面试题-谈谈你对Java平台的理解
平台无关性 GC 语言特性 面向对象 类库 异常处理 一次编译到处运行 JVM如何加载Class文件 Java反射 ClassLoader 种类 双亲委派机制 loadcalss和forName
- python 列表 字典转json
一.Dictionary 转为JSON 将dict转为JSON,这里利用包json import jsonaItem = {}aItem["id"] = "2203&qu ...
- Cookie中存放数据l加密解密的算法
public class CookieUtil { /** * * @param response HttpServletResponse类型的响应 * @param cookie 要设置httpOn ...
- C#基于联通短信Sgip协议构建短信网关程序
此软件基于中国联通Sgip协议程序接口,适合在中国联通申请了短信发送端口的公司使用.短信群发已经成为现在软件系统.网络营销等必不可少的应用工具.可应用在短信验证.信息群发.游戏虚拟商品购买.事件提醒. ...
- Spring中使用事务搭建转账环境 转账操作,
演示不使用事务出现异常情况 Dao层两个方法lessMoney()和moreMoney() package com.swift; import org.springframework.jdbc.cor ...
- (75)zabbix_server.conf配置文件详解
############ GENERAL PARAMETERS ################# ### Option: ListenPort# Listen port for trapper.# ...
- Linux 安装Nginx+PHP+MySQL教程
一.安装nginx 通过yum安装openssl: yum -y install openssl openssl-devel 通过yum安装pcre: yum -y install pcre-deve ...
- Python学习笔记:PyInstaller(exe程序打包)
PyInstaller可以将Python程序打包成一个exe程序来独立运行,用户使用时只需要执行这个exe文件即可,不需要在机器上再安装Python及其他包就可运行了.另外,PyInstaller相较 ...
- 04 Django模板
基本概念 作为Web框架,Django提供了模板,用于编写html代码,还可以嵌入模板代码更快更方便的完成页面开发,再通过在视图中渲染模板,将生成最终的html字符串返回给客户端浏览器 模版致力于表达 ...