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 |
那位牛哥帮忙看看那里错了#include<iostream> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; #define MAX 194621.00 int co(double a,double b) { if(fabs(a-MAX)<=1e-6&&fabs(b-MAX)<=1e-6) return 0; if(fabs(a-MAX)<=1e-6) return 1; else if(fabs(b-MAX)<=1e-6) return -1; if(fabs(a-b)<=1e-6) return 0; if(a-b>1e-6) return 1; else if(b-a>1e-6) return -1; } void s(double& a,double& b) { double t; t=a; a=b; b=t; } struct LI { double x1,y1; double x2,y2; double k,b; bool operator <(const LI &a) const { if(co(k,MAX)==0&&co(a.k,MAX)==0) { if(co(b,a.b)==0) { if(co(y1,a.y1)==0) { if(co(y2,a.y2)>0) return 0; else return 1; } else if(co(y1,a.y1)>0) return 0; else return 1; } else if(co(b,a.b)>0) return 0; else return 1; } if(co(k,a.k)==0) { if(co(b,a.b)==0) { if(co(x1,a.x1)==0) { if(co(x2,a.x2)>0) return 0; else return 1; } else if(co(x1,a.x1)>0) return 0; else return 1; } else if(co(b,a.b)>0) return 0; else return 1; } else if(co(k,a.k)>0) return 0; else return 1; } }; LI line[10001]; int p[100]; int main() { int n,m; int i,k=0; double z,c; while(true) { scanf("%d",&n); if(n==0) break; for(i=0;i<n;i++) { scanf("%lf%lf%lf%lf",&line[i].x1,&line[i].y1,&line[i].x2,&line[i].y2); if(co(line[i].x1,line[i].x2)==0) { if(co(line[i].y1,line[i].y2)>0) { s(line[i].x1,line[i].x2); s(line[i].y1,line[i].y2); } } else if(co(line[i].x1,line[i].x2)>0) { s(line[i].x1,line[i].x2); s(line[i].y1,line[i].y2); } if(co(line[i].x1,line[i].x2)==0) { line[i].k=MAX; line[i].b=line[i].x1; } else { line[i].k=(line[i].y2-line[i].y1)/(line[i].x2-line[i].x1); line[i].b=line[i].y1-line[i].x1*line[i].k; } } sort(line,line+n); m=1; z=line[0].x2; // p[0]=1; // k=1; for(i=1;i<n;i++) { if(co(line[i].k,MAX)==0&&co(line[i-1].k,MAX)!=0) c=line[i].y2; if(co(line[i].k,MAX)==0&&co(line[i-1].k,MAX)==0) { if(co(line[i].b,line[i-1].b)!=0) m++; else if(co(line[i].y1,c)>0) m++; if(co(line[i].b,line[i-1].b)!=0) c=line[i].y2; else if(co(line[i].y2,c)>0) c=line[i].y2; } else { if(co(line[i].k,line[i-1].k)!=0) m++; else if(co(line[i].b,line[i-1].b)!=0) m++; else if(co(line[i].x1,z)>0) m++; } if(co(line[i].k,line[i-1].k)!=0) z=line[i].x2; else if(co(line[i].b,line[i-1].b)!=0) z=line[i].x2; else if(co(line[i].x2,z)>0) z=line[i].x2; } // p[k++]=m; printf("%d\n",m); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator