bzoj1173: [Balkan2007]point

Source: Internet
Author: User
Tags gcd

Description

Gives a point on n three-dimensional space. Ask how many straight lines there are at least three points in the line.

Input

The first line gives the number of characters n,n under [4,1000] n lines, three digits per line, to describe the coordinates of the point, whose value is in [ -10000,10000]

Output

How many lines are there?

Enumerates the direction of the line, constructs a graph for each direction, if the two points between lines in this direction is connected to the edge, each of at least three points of the Unicom block represents a straight line

#include <cstdio>#include<algorithm>inlineintgcdintXinty) {     for(intz;y;z=x,x=y,y=z%y); returnx;}intN;structpos{intx, Y, Z voidfix () {intg=gcd (gcd (x, y), z); X/=g;y/=g;z/=G; if(x!=0?x<0: y!=0?y<0:z<0) x=-x,y=-y,z=-Z; }}ps[1007];BOOL operator==(ConstPos&a,ConstPOS&AMP;B) {returna.x==b.x&&a.y==b.y&&a.z==b.z;}BOOL operator< (ConstPos&a,ConstPOS&AMP;B) {returna.x!=b.x?a.x<b.x:a.y!=b.y?a.y<b.y:a.z<b.z;} POSoperator-(POS A,pos b) {return(POS) {a.x-b.x,a.y-b.y,a.z-b.z};}structline{intb; Pos v;} as[1007*555];BOOL operator< (ConstLine&a,ConstLINE&AMP;B) {returna.v<B.V;}intap=0, ans=0;intes[1000007],enx[1000007],e0[1007],ep=2, ds[1007],dp=0, t,tk[1007];intDfsintW) {    intC=1; TK[W]=T;  for(intI=e0[w];i;i=Enx[i]) {        intu=Es[i]; if(tk[u]!=t) c+=dfs (U); }    returnC;}voidAdde (intAintb) {    if(!e0[a]) ds[dp++]=A; if(!e0[b]) ds[dp++]=b; ES[EP]=b;enx[ep]=e0[a];e0[a]=ep++; ES[EP]=a;enx[ep]=e0[b];e0[b]=ep++;}intMain () {scanf ("%d",&N);  for(intI=1; i<=n;++i) scanf ("%d%d%d",&ps[i].x,&ps[i].y,&ps[i].z);  for(intI=1; i<=n;++i) {         for(intj=1; j<i;++j) {            ( as[Ap++]= (line) {i,j,ps[i]-Ps[j]}).        V.fix (); }} std::sort ( as, as+AP);  for(intI=0, j=0;i<ap;) { for(;j<ap&& as[i].v== as[j].v;++j);  for(++t;i<j;++i) Adde ( as[I].a, as[i].b];  for(intk=0; k<dp;++k)if(Dfs (ds[k]) >=3)++ans;  while(DP) e0[ds[--dp]]=0; ep=2; } printf ("%d\n", ans); return 0;}

bzoj1173: [Balkan2007]point

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.