标签:contest ack tac iostream 链接 intersect else 代码 mes
题目链接:https://vjudge.net/contest/276358#problem/D
题目大意:每一次给你两条直线,然后问你这两条直线的关系(平行,共线,相交(输出交点))。
具体思路:先判断共线,再去判断平行,其次是相交,这些都能通过叉积来判断。
具体的证明过程晚会发吧。
AC代码:
1 #include<iostream> 2 #include<stack> 3 #include<stdio.h> 4 #include<iomanip> 5 #include<cmath> 6 using namespace std; 7 # define ll long long 8 const int maxn = 300+100; 9 const double eps = 1e-8; 10 int cal(int x1,int y1,int x2,int y2){ 11 return x1*y2-x2*y1; 12 } 13 int main( ) { 14 int T; 15 int x1,y1,x2,y2; 16 int x3,y3,x4,y4; 17 double a1,a2,b1,b2,c1,c2; 18 scanf("%d",&T); 19 printf("INTERSECTING LINES OUTPUT\n"); 20 while(T--){ 21 scanf("%d %d %d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); 22 if(cal(x2-x1,y2-y1,x3-x1,y3-y1)==0&&cal(x2-x1,y2-y1,x4-x1,y4-y1)==0) { 23 printf("LINE\n"); 24 } 25 else if(cal(x2-x1,y2-y1,x4-x3,y4-y3)==0){ 26 printf("NONE\n"); 27 } 28 else { 29 a1=y1-y2; 30 a2=y3-y4; 31 b1=x2-x1; 32 b2=x4-x3; 33 c1=x1*y2-x2*y1; 34 c2=x3*y4-x4*y3; 35 printf("POINT %.2lf %.2lf\n",(c1*b2-c2*b1)/(a2*b1-a1*b2),(c1*a2-c2*a1)/(b2*a1-b1*a2)); 36 } 37 } 38 printf("END OF OUTPUT\n"); 39 return 0; 40 }
判断线段之间的关系(D - Intersecting Lines POJ - 1269 )
标签:contest ack tac iostream 链接 intersect else 代码 mes
原文地址:https://www.cnblogs.com/letlifestop/p/10339422.html