hdu1027Ignatius and the Princess II <vector>

原创 2015年07月08日 17:16:28

搜分类是数学或者STL,看题解数学的方法没看懂,STL的vector真心赞

http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html 讲next_permutation 好东西啊

本题属于链接的最后一种情况吧

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,i;
int main()
{
    while(cin>>n>>m)
    {
        vector<int>ivec;
        ivec.clear();
        vector<int>::iterator iter;
        for(i=1;i<=n;i++) ivec.push_back(i);
        for(i=1;i<m;i++) next_permutation(ivec.begin(),ivec.end());
        for(i=0,iter=ivec.begin();iter!=ivec.end();++i,++iter)//iter之前一直写成i编译提示我需要运算符重载orz
         cout<<(i==0?"":" ")<<*iter;
         cout<<endl;
    }
    return 0;
}

Problem Description
Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5166 says, "I have three question for you, if 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?
 

Input
The input contains several test cases. Each test case consists of two numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume that there is always a sequence satisfied the BEelzebub's demand. The input is terminated by the end of file.
 

Output
For each test case, you only have to output the sequence satisfied the BEelzebub's demand. When output a sequence, you should print a space between two numbers, but do not output any spaces after the last number.
 

Sample Input
6 4 11 8
 

Sample Output
1 2 3 5 6 4 1 2 3 4 5 6 7 9 8 11 10

版权声明:⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄hiahiahia 欢迎斧正 举报

相关文章推荐

HDU 1027 Ignatius and the Princess II【STL- next_permutation全拍列】

题意:输入n和m,求1-n的第m个全排列。 有了STL的next_permutation,妈妈再也不用担心我会WA了。。。

HDU 1027 Ignatius and the Princess II [康托逆展开]【数学】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027——————————————–.Ignatius and the Princess IITime ...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

Hdu1027 Ignatius and the Princess II

Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav...

【STL相关】hdu 1027 Ignatius and the Princess II【STL】

Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

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 ...

【STL】hdu 1027 Ignatius and the Princess II

next_permutation函数的应用

HDU1027_Ignatius and the Princess II_非模拟做法

Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

HDU1027Ignatius and the Princess II(排序)

题目大意:给出1,2……n的序列,输出第m小的序列;1,2,3,……n是最小的序列,1,2,3……n,n-1是第2小的序列;给出你两个数n,m,(n表示有n个数,m表示第m小的序列),输出第m小的序列...

next_permutation & prev_permutation & hdu 1027 Ignatius and the Princess II

两个STL库函数next_permutation & prev_permutation本来不会,但看了别人的blog后有点感觉了!他的blog中没有样例(题解),而我有,所以我写成原创应该不算过分吧!...

排列-hdu_1027_Ignatius and the Princess II

题目链接:点击打开链接 题目描述: Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory L...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)