| ||||||||||
| 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 | |||||||||
排序之后扫描那里太复杂了,要简化一下In Reply To:TLE~~~大牛请指教一下#_# Posted by:bluetiger at 2006-03-25 12:47:02 可以取定n1作参考,然后在n2里面找相反数
> #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