1. 程式人生 > >ignitius and princess 2(全排列)

ignitius and princess 2(全排列)

pac row scan 代碼 ring stdio.h color clas rip

A - Ignatius and the Princess II

STL中的algorithm 的全排列應用

#include<stdio.h>  
#include<string.h>  
#include<algorithm>  
#define INF 0x3f3f3f3f  
#define ll long long  
#define N 100010  
using namespace std;  
int a[N];  
int main()  
{  
    int n,m;  
    while(scanf("%d%d",&n,&m)!=EOF)  
    {  
        
for(int i=1;i<=n;i++) a[i]=i; int k=1; while(next_permutation(a+1,a+n+1))//全排列函數 { k++; if(k==m) break; } for(int i=1;i<n;i++) printf("%d ",a[i]); printf("%d\n",a[n]); }
return 0; }

(這為博客找的解題代碼)

ignitius and princess 2(全排列)