http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264
分析:
利用向量的叉积 若有一条线段为AB 两个点C、D 如果这两个点在线段AB的两侧 那么向量AB×向量AC与向量AB×向量AD的结果正好一正一负 因为它们相乘所得到的向量方向相反 利用这个性质判断点AB是否在线段CD两侧并且点CD是否在选段AB两侧同时满足即相交 向量叉乘公式 设两向量分别为 a(x1,y1) b(x2,y2) 则 a×b=x1*y2-x2*y1
AC代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define mset(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define FIN freopen("input","r",stdin)
#define FOUT freopen("output","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
struct node{
double x,y;
}A,B,C,D;
double cal(node a,node b,node c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int main (){
int t;
scanf ("%d",&t);
while (t--){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y);
if (cal(A,B,C)*cal(A,B,D)<=0&&cal(C,D,A)*cal(C,D,B)<=0) printf ("Yes\n");
else printf ("No\n");
}
return 0;
}