HDU 1027 Ignatius and the Princess II

全排列,next_permutation


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

#define sf scanf
#define pf printf
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define dbg(x) cerr << "Line:" <<  __LINE__ << " : " << #x << " = " << (x) << endl
#define nMax 1000000
#define ll long long
#define CLR(a) memset((a),0,sizeof((a)))


int n,m;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	while(sf("%d%d",&n,&m)==2) {
		vector<int> a(n);
		rep(i,n) a[i]=i+1;
		rep(i,m-1) next_permutation(a.begin(),a.end());
		rep(i,n) {
			if(i) pf(" ");
			pf("%d",a[i]);
		}pf("\n");
	}
	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章