HDOJ 1027 Ignatius and the Princess II

mac2022-06-30  43

 

题意:给一个树组,长度为1,2,3。。。n ,求全排序里面第m小的序列。

思路:调用库函数next_permutation 水过

其中库中另一函数prev_permutation与next_permutation相反,由原排列得到字典序中上一次最近排列。

 

69395642012-10-18 11:10:31Accepted102731MS260K306 BC++罗维

 

View Code 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int main() 6 { 7 int f[1002]; 8 int n, m, i; 9 while (cin>>n>>m) 10 { 11 for (i=0; i<n; i++) 12 f[i] = i+1; 13 m--; 14 while(m--) 15 next_permutation(f, f+n); 16 cout<<f[0]; 17 for (i=1; i<n; i++) 18 cout<<" "<<f[i]; 19 cout<<endl; 20 } 21 }

 

 

转载于:https://www.cnblogs.com/lv-2012/archive/2012/10/18/2729150.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)