标签:out style tac bool any nat man always ane
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10924 Accepted Submission(s): 5393
1 #include<algorithm> 2 #include<iostream> 3 #include<iomanip> 4 #include<cstdlib> 5 #include<cstring> 6 #include<vector> 7 #include<cstdio> 8 #include<stack> 9 #include<queue> 10 #include<cmath> 11 #include<ctime> 12 #include<set> 13 #include<map> 14 #define ll long long 15 #define rep(i,a,b) for(register int i=a;i<=b;i++) 16 #define inf 1<<29 17 #define re register 18 using namespace std; 19 #define eps 1e-6 20 const int N=110; 21 struct point{ 22 double x,y; 23 }d[2]; 24 struct line{ 25 double k,b; 26 double l,r,ly,ry; 27 }L[N]; 28 int n; 29 inline bool pd(double x,double y,int k) { 30 return (x>=L[k].l&&x<=L[k].r&&y>=L[k].ly&&y<=L[k].ry); 31 } 32 inline bool judge(int i,int j) { 33 if(fabs(L[i].k-L[j].k)<=eps) return 0; 34 if(fabs(L[i].k-0)<=eps&&fabs(L[j].k-0)<=eps) return 0; 35 if(fabs(L[i].k-0)>eps&&fabs(L[j].k-0)>eps) { 36 double x=(L[j].b-L[i].b)/(L[i].k-L[j].k), 37 y=L[i].k*x+L[i].b; 38 if(pd(x,y,i)&&pd(x,y,j)) return 1; 39 else return 0; 40 } 41 if(fabs(L[i].k-0)<=eps) { 42 double x=L[i].l; 43 double y=L[j].k*x+L[j].b; 44 return (y>=L[j].ly&&y<=L[j].ry); 45 } 46 double x=L[j].l; 47 double y=L[i].k*x+L[i].b; 48 return (y>=L[i].ly&&y<=L[i].ry); 49 } 50 int main() { 51 freopen("Y.in","r",stdin); 52 freopen("Y.out","w",stdout); 53 while(scanf("%d",&n)&&n) { 54 for(int i=1;i<=n;i++) { 55 scanf("%lf%lf%lf%lf",&d[0].x,&d[0].y,&d[1].x,&d[1].y); 56 L[i].l=min(d[0].x,d[1].x),L[i].r=max(d[0].x,d[1].x); 57 L[i].ly=min(d[0].y,d[1].y),L[i].ry=max(d[0].y,d[1].y); 58 if(fabs(d[1].x-d[0].x)<=eps) 59 L[i].k=0; 60 else { 61 L[i].k=(d[1].y-d[0].y)/(d[1].x-d[0].x); 62 L[i].b=d[0].y-L[i].k*d[0].x; 63 } 64 } 65 int ans=0; 66 for(int i=1;i<n;i++) 67 for(int j=i+1;j<=n;j++) 68 if(judge(i,j)) ans++; 69 cout<<ans<<endl; 70 } 71 return 0; 72 }
标签:out style tac bool any nat man always ane
原文地址:http://www.cnblogs.com/ypz999/p/7107127.html