zoukankan      html  css  js  c++  java
  • POJ 1883 排序 ( 水 + next_permutation )

    链接:传送门
    题意:
    思路:next_permutation(),水,但是要注意一点的是如果是最后一个排列next_permutation会返回第一个排列并结束,所以如果到了最后一个排列还不是第k个就处理一下即可

    /*************************************************************************
        > File Name: 31.cpp
        > Author:    WArobot 
        > Blog:      http://www.cnblogs.com/WArobot/ 
        > Created Time: 2017年04月19日 星期三 22时15分06秒
     ************************************************************************/
    
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    int t,n,k;
    int s[1034];
    int main(){
    	scanf("%d",&t);
    	while(t--){
    		scanf("%d%d",&n,&k);
    		for(int i=0;i<n;i++)	scanf("%d",s+i);
    		int cnt = 0 , i;
    		do{
    			cnt++;
    			for(i=0;i<n;i++)
    				if(s[i]!=n-i)	break;
    			if(i==n){
    				cnt++;
    				for(int i=0;i<n;i++)	s[i]=i+1;
    			}
    			if(cnt == k+1)	break;
    		}while(next_permutation(s,s+n));
    		for(int i=0;i<n;i++)	printf("%d%c",s[i],i==n-1?'
    ':' ');
    	}
    	return 0;
    }
  • 相关阅读:
    Use HTTPS instead of HTTP
    Disable SSLv3
    JIRA Installation
    排序算法之简单选择排序
    排序算法之冒泡排序
    三本优秀的Python教程
    ubuntu*set*up
    程序员的十层楼(转载)
    drools spring config的问题
    MySQL Performance Tuning
  • 原文地址:https://www.cnblogs.com/WArobot/p/6736334.html
Copyright © 2011-2022 走看看