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 ( ...
随机推荐
- Android(java)学习笔记131:关于构造代码块,构造函数的一道面试题(华为面试题)
1. 代码实例: package text; public class TestStaticCon { public static int a = 0; static { a = 10; System ...
- Problem D: 小平查密码
Problem D: 小平查密码 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 194 Solved: 40[Submit][Status][Web ...
- 2406: C语言习题 求n阶勒让德多项式
2406: C语言习题 求n阶勒让德多项式 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 961 Solved: 570[Submit][Status ...
- java基础—this关键字
一.this关键字
- 如何通过修改文件添加用户到sudoers上
su - root chmod u+w /etc/sudoers (该文件没有写权限, 修改)vim /etc/sudoers 按下 I 键进行编写 # User privilege speci ...
- Bootstrap标签页(Tab)插件事件
事件 下表列出了标签页(Tab)插件中要用到的事件.这些事件可在函数中当钩子使用. 事件 描述 实例 show.bs.tab 该事件在标签页显示时触发,但是必须在新标签页被显示之前.分别使用 even ...
- Bootstrap历练实例:动画的进度条
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- cocos2d-x之CCCardinalSplineBy
CCCardinalSplineBy概念 这个类是样条曲线动作,其创建函数CCCardinalSplineBy::create(float duration, cocos2d::CCPointArra ...
- java上传附件,批量下载附件(一)
上传附件代码:借助commons-fileupload-1.2.jar package com.str; import java.io.BufferedInputStream;import java. ...
- Python中类的声明,使用,属性,实例属性,计算属性及继承,重写
Python中的类的定义以及使用: 类的定义: 定义类 在Python中,类的定义使用class关键字来实现 语法如下: class className: "类的注释" 类的实体 ...