| ||||||||||
| 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 | |||||||||
用归排序输入的四个数组排序,两两相加后用归并排序会比快排更快
不信试试看
在处理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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator