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

Re:同一解法

Posted by zhangfeifei at 2010-08-23 21:14:29 on Problem 1674 and last updated at 2010-08-23 21:19:49
In Reply To:同一解法 Posted by:zhangfeifei at 2010-08-23 21:02:40
再提一点,就是不必交换,只需赋值。注意到运行到第 i 次时,交换 i 和 i 位置上的数值。因为 i 是从 1 开始逐个往上累加的,
所以 i 交换过后根本就没用过。所以就直接对后面的赋值。
int getRes(int n)
{
	int i,sum=0;
	for(i=1;i<=n;i++)
	{
		if(num[i] != i)
		{
			sum ++;
			num[index[i]] = num[i];
			index[num[i]] = index[i];
		}
	}
	return sum;
}
但,还是 47 ms,不知道怎地。

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