JZOJ8.11(C组)直角三角形

    xiaoxiao2024-12-27  18

    题目:

    平面上给定N个两两不同的整点,统计以给定的点为顶点,且直角边平行于坐标轴的直角三角形数。

    分析:

    直接枚举每个点坐标即可

    附上代码:

    type   arr=array [1..100002] of longint; var   x,y,x1,y1,x2,y2,numx,numy:arr;   n:longint; procedure qsort(l,r:longint; var a:arr); var   i,j,mid,temp:longint; begin   if l>=r then     exit;   mid:=a[l+random(r-l+1)];i:=l;j:=r;   repeat     while a[i]<mid do       inc(i);     while a[j]>mid do       dec(j);     if i<=j then       begin         temp:=a[i];a[i]:=a[j];a[j]:=temp;         inc(i);dec(j);       end;   until i>j;   qsort(l,j,a);   qsort(i,r,a); end; procedure init; var   i:longint; begin   readln(n);   for i:=1 to n do     begin       readln(x[i],y[i]);       x1[i]:=x[i];       y1[i]:=y[i];     end; end; procedure main; var   i,k,k1,temp,l1,r1,t,mid,ans,num1,num2:longint; begin   ans:=0;qsort(1,n,x);qsort(1,n,y);k:=1;x2[k]:=x[1];   for i:=2 to n do     begin       if x[i]=x[i-1] then         inc(numx[k])       else         begin           inc(k);           x2[k]:=x[i];         end;     end;   k1:=1;   y2[k1]:=y[1];   for i:=2 to n do     begin       if y[i]=y[i-1] then         inc(numy[k1])       else         begin           inc(k1);           y2[k1]:=y[i];         end;     end;   x:=x1;   y:=y1;   for i:=1 to n do     begin       temp:=x[i];t:=y[i];l1:=1;r1:=k;       while l1<=r1 do         begin           mid:=(l1+r1) shr 1;           if x2[mid]=temp then             break;           if x2[mid]>temp then             r1:=mid-1           else             l1:=mid+1;         end;       if x2[mid]=temp then         num1:=numx[mid];       l1:=1;r1:=k1;       while l1<=r1 do         begin           mid:=(l1+r1) shr 1;           if y2[mid]=t then             break;           if y2[mid]>t then             r1:=mid-1           else             l1:=mid+1;         end;       if y2[mid]=t then         num2:=numy[mid];       ans:=ans+num1*num2;     end;   writeln(ans); end; begin   init;   main; end.

    转载请注明原文地址: https://ju.6miu.com/read-1295038.html
    最新回复(0)