题意:给出两个数m,n,求出1-m的第n个全排列
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027
思路:用next_permutation函数就行
注意点:无
以下为AC代码:
Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
12966433 | 2015-02-18 23:48:00 | Accepted | 1027 | 31MS | 1192K | 1379 B | G++ | luminous11 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
//const double pi = acos(-1);
//const double eps = 1e-10;
//const int dir[[4][2] = { 1,0, -1,0, 0,1, 0,-1 };
int ans[1005];
int cnt;
void init()
{
cnt = 0;
for ( int i = 0; i < 1005; i ++ ){
ans[i] = i;
}
}
int main()
{
ios::sync_with_stdio( false );
int m, n;
while ( cin >> m >> n ){
init();
do{
cnt ++;
if ( cnt == n ){
for ( int i = 1; i <= m; i ++ ){
cout << ans[i];
if ( i != m )
cout << ' ';
}
cout << endl;
break;
}
}while( next_permutation ( ans + 1, ans + 1 + m ) );
}
return 0;
}