Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手指点:怎样改才不超时,郁闷中.......

Posted by jinweiliang at 2009-04-05 15:56:25 on Problem 1833
// 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator