标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12863 | Accepted: 5712 |
Description
Input
Output
Sample Input
5 0 0 4 4 0 4 4 0 5 0 7 6 1 0 2 3 5 0 7 6 3 -6 4 -3 2 0 2 27 1 5 18 5 0 3 4 0 1 2 2 5
Sample Output
INTERSECTING LINES OUTPUT POINT 2.00 2.00 NONE LINE POINT 2.00 5.00 POINT 1.07 2.20 END OF OUTPUT
给出n对直线。。。问每对直线的位置关系(平行,重合,相交,相交的话要求出交点)
嗯。
1 /************************************************************************* 2 > File Name: a.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年11月06日 星期五 09时48分39秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #include<cctype> 21 #define fst first 22 #define lson l,m,rt<<1 23 #define rson m+1,r,rt<<1|1 24 #define ms(a,x) memset(a,x,sizeof(a)) 25 using namespace std; 26 const int dx4[4]={1,0,0,-1}; 27 const int dy4[4]={0,-1,1,0}; 28 typedef long long LL; 29 #define sec second 30 const int inf = 0x3f3f3f3f; 31 const double eps=1E-8; 32 int n; 33 34 int dblcmp( double d) 35 { 36 return d<-eps?-1:d>eps; 37 } 38 39 struct point 40 { 41 double x,y; 42 point(){} 43 point(double _x,double _y): 44 x(_x),y(_y){}; 45 void input() 46 { 47 scanf("%lf%lf",&x,&y); 48 } 49 void output() 50 { 51 printf("%.2f %.2f\n",x,y); 52 } 53 point sub(point p) 54 { 55 return point(x-p.x,y-p.y); 56 } 57 double det(point p) 58 { 59 return x*p.y-y*p.x; 60 } 61 62 }; 63 64 struct line 65 { 66 point a,b; 67 line(){} 68 void input() 69 { 70 a.input(); 71 b.input(); 72 } 73 74 75 76 int relation(point p) 77 { 78 int c = dblcmp(p.sub(a).det(b.sub(a))); 79 if (c<0) return 1; 80 if (c>0) return 2; 81 return 3; 82 } 83 bool parallel(line v) 84 { 85 return dblcmp(b.sub(a).det(v.b.sub(v.a)))==0; 86 } 87 //0平行 88 //1重合 89 //2相交 90 int linecrossline(line v) 91 { 92 if ((*this).parallel(v)) 93 { 94 return v.relation(a)==3; 95 } 96 return 2; 97 } 98 99 point crosspoint(line v) 100 { 101 double a1 = v.b.sub(v.a).det(a.sub(v.a)); 102 double a2 = v.b.sub(v.a).det(b.sub(v.a)); 103 return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1)); 104 } 105 }li[15][3]; 106 int main() 107 { 108 #ifndef ONLINE_JUDGE 109 freopen("in.txt","r",stdin); 110 #endif 111 scanf("%d",&n); 112 for ( int i = 1 ; i <= n ; i++) 113 { 114 li[i][1].input(); 115 li[i][2].input(); 116 } 117 118 puts("INTERSECTING LINES OUTPUT"); 119 for ( int i = 1 ; i <= n ; i++) 120 { 121 int tmp = li[i][1].linecrossline(li[i][2]); 122 // cout<<"tmp:"<<tmp<<endl; 123 if (tmp==0) 124 { 125 puts("NONE"); 126 } 127 if (tmp==1) 128 { 129 puts("LINE"); 130 } 131 if (tmp==2) 132 { 133 printf("POINT "); 134 li[i][1].crosspoint(li[i][2]).output(); 135 } 136 } 137 puts("END OF OUTPUT"); 138 139 140 141 142 143 #ifndef ONLINE_JUDGE 144 fclose(stdin); 145 #endif 146 return 0; 147 }
poj 1269 Intersecting Lines (计算几何)
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4942200.html