zoukankan      html  css  js  c++  java
  • POJ 1833

    使用STL中的next_permutation(opt1,opt2)函数更容易实现。opt1为数组头地址,opt2为数组长度。排列是按字典序的。

    当找到下一个排列时,返回真,否则返回假,此时,把原数组重排一次。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    
    int p[1100];
    
    int main(){
    	int T; int n,nt;
    	scanf("%d",&T);
    	while(T--){
    		scanf("%d%d",&n,&nt);
    		for(int i=0;i<n;i++)
    		scanf("%d",&p[i]);
    		for(int i=0;i<nt;i++){
    			if(!next_permutation(p,p+n))
    			sort(p,p+n);
    		}
    		printf("%d",p[0]);
    		for(int i=1;i<n;i++)
    		printf(" %d",p[i]);
    		printf("
    ");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    非空约束
    leetcode208
    leetcode207
    leetcode395
    leetcode116
    leetcode105
    leetcode131
    leetcode73
    leetcode200
    leetcode17
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3991459.html
Copyright © 2011-2022 走看看