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

自制next_permutation() 400+MS过 //这里可以用2分查找进行优化

Posted by CydorniaKnight at 2009-02-25 14:57:06 on Problem 1833
void NextPermutation()
{
	int i,j,n1=n-1,k;
	for(i=n1-1;i>=0;--i)
		if(num[i]<num[i+1])
			break;
	if(i<0){
		MegerSort(0,n);
		return;
	}
	for(j=n1;j>=i+1;--j)//这里可以用2分查找进行优化
		if(num[j]>num[i])
			break;
	k=num[i];
	num[i]=num[j];
	num[j]=k;
	MegerSort(i+1,n);
}

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