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 frkstyc at 2006-03-30 13:06:16 on Problem 2785
In Reply To:用归排序 Posted by:gemenhao at 2006-03-30 13:00:12
瓶颈根本不在这里

> 输入的四个数组排序,两两相加后用归并排序会比快排更快
> 不信试试看
> 在处理a+b+c+d=0
> 可以写作 a + b= - c -d
> c 和d 的数组取反
> 这样只要查找 两两数组中相等的就可
> 查找的核心代码
> 	__int64 cnt = 0;
> 	int p1 = 0,p2 = 0;
> 	while(p1 < n && p2 < n)
> 	{
> 		if(n1[p1] > n2[p2])
> 			p2++;
> 		else if(n1[p1] < n2[p2])
> 			p1++;
> 		else
> 		{
> 			int c1 = 1,c2 = 1;
> 			p1++,p2++;
> 			while(n1[p1-1] == n1[p1] && p1++ < n)
> 				c1++;
> 			while(n2[p2-1] == n2[p2] && p2++ < n)
> 				c2++;
> 			cnt += c1*c2;
> 		}
> 	}

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