HDU1027 强大的STL



再一次见识到了STL的强大,,ORZ。。。

eg:b[3]={1,2,3};(有序)

有3!个全排列


next_permutation(b+0, b + 3); (递增)

The 3! possible permutations with 3 elements:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
After loop: 1 2 3
相对的有prev_permutation为递减


#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include <queue>
#include <stack>
#include<algorithm>
#include<set>
using namespace std;
#define inf 2147483647
#define eps 1e-8
#define LL long long
#define M 50005					
#define mol 1000000007
int main()
{
	int n,m;
	int a[]={0,1,2,6,24,120,720,5040,40320},b[1005]={0};
	while(~scanf("%d%d",&n,&m))
	{
		int i,j,k;
	   for(i=0;i<10;i++)
	     if(m>=a[i]&&m<=a[i+1]){
			 k=i+1;break;
	   }
	   for(j=1;j<=n-k;j++)
		   printf("%d ",j);
	   for(i=n-k+1,j=0;i<=n;i++,j++)
	   {
	      b[j]=i;
	   }
	   m--;
	   while(m--)
	   {
	      next_permutation(b+0, b + k);  
	   }
	   for(i=0;i<j-1;i++)
		   printf("%d ",b[i]);
	   printf("%d\n",b[j-1]);
	}
return 0;
}



你可能感兴趣的:(HDU1027 强大的STL)