Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
高手指点:怎样改才不超时,郁闷中.......// 1833.cpp : Defines the entry point for the console application. // //#include "stdafx.h" #include <stdio.h> #include<algorithm> using namespace std; int main() { int m; //freopen("1833.txt","r",stdin); scanf("%d",&m); while(m--) { int n,j,k,i,a[1025]; scanf("%d %d",&n,&k); for(i=0;i<n;i++) { scanf("%d",&a[i]); //printf("%d",a[i]); }//printf("\n"); i=0; j=1; while(1) { if(!next_permutation(a,a+n))//产生当前排列的后一个排列 { for(i=1;i<n;i++) printf("%d ",i); printf("%d\n",i); goto loop; } else if(next_permutation(a,a+n)) { j++; if(j==k) { for(i=0;i<n-1;i++) printf("%d ",a[i]); printf("%d\n",a[i]); goto p2; } } } p2:; loop:; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator