| ||||||||||
| 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 | |||||||||
TLE~~~大牛请指教一下#_##include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a[4001],b[4001],c[4001],d[4001],n1[16000001],n2[16000001];
int num,n;
__int64 cnt;
int main()
{
int i,j,p1,p2,c1,c2,pt1,pt2;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
num=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
n1[num]=a[i]+b[j],n2[num]=c[i]+d[j],num++;
sort(n1,n1+num);
sort(n2,n2+num);
p1=0;p2=num-1;cnt=0;
while(p1<num&&p2>=0)
{
if(n1[p1]+n2[p2]==0)
{
c1=c2=1;
pt1=p1;pt2=p2;
while(p1+1<num&&n1[pt1]==n1[++p1])c1++;
while(p2-1>=0&&n2[pt2]==n2[--p2])c2++;
cnt+=c1*c2;
}
else if(n1[p1]<=0&&n2[p2]>=0)
{
if(abs(n1[p1])<abs(n2[p2]))p2--;
else p1++;
}
else if(n1[p1]>=0&&n2[p2]<=0)
{
if(abs(n1[p1])<abs(n2[p2]))p1++;
else p2--;
}
else if(n1[p1]<=0&&n2[p2]<=0)p1++;
else if(n1[p1]>=0&&n2[p2]>=0)p2--;
}
printf("%I64d\n",cnt);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator