德莱联盟
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
-
欢迎来到德莱联盟。。。。
德莱文。。。
德莱文在逃跑,卡兹克在追。。。。
我们知道德莱文的起点和终点坐标,我们也知道卡兹克的起点和中点坐标,问:卡兹克有可能和德莱文相遇吗?,并且保证他们走的都是直线。
- 输入
- 几组数据,一个整数T表示T组数据
每组数据 8个实数,分别表示德莱文的起点和终点坐标,以及卡兹克的起点和终点坐标 - 输出
- 如果可能 输出 Interseetion,否则输出 Not Interseetion
- 样例输入
-
2 -19.74 7.14 22.23 -27.45 -38.79 -5.08 47.51 34.01 -8.61 9.91 -32.47 6.47 -3.81 -16.1 7.82 -6.37
- 样例输出
-
Interseetion Not Interseetion
# include <iostream> # include <cstdio> # include <algorithm> using namespace std; struct node { double x, y; }st1,st2,ed1,ed2; double fun(node a, node b, node c)//叉乘 { return a.x*b.y + b.x*c.y + c.x*a.y - a.x*c.y - b.x*a.y - c.x*b.y; } int main() { int t; double s1,s2,s3,s4; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&st1.x,&st1.y,&ed1.x,&ed1.y,&st2.x,&st2.y,&ed2.x,&ed2.y); if((max(st1.x,ed1.x)>=min(st2.x,ed2.x)||max(st2.x,ed2.x)>=min(st1.x,ed1.x))&& (max(st1.y,ed1.y)>=min(st2.y,ed2.y)||max(st2.y,ed2.y)>=min(st1.y,ed1.y)))//快速排斥 { s1 = fun(st1, ed1, st2);//跨立 s2 = fun(st1, ed1, ed2); s3 = fun(st2, ed2, st1); s4 = fun(st2, ed2, ed1); if(s1*s2<=0 && s3*s4<=0) puts("Interseetion"); else puts("Not Interseetion"); } else puts("Not Interseetion"); } return 0; }参考博文:http://blog.csdn.net/LYHVOYAGE/article/details/24601151#