題目鏈接:點擊打開鏈接
解題思路:
用直線和點的關係來判斷.把A和B這條線段看成一條直線,分別看C和D關於這條直線的位置關係,如果一正一負,那麼必然相交.
完整代碼:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <string>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <time.h>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;
const int maxn = 100001;
struct point
{
double x , y;
point(double a , double b) : x(a) , y(b) {};
point() {};
void input()
{
scanf("%lf%lf",&x,&y);
}
};
bool line_make_point(point a , point b , point c , point d)
{
double C = (c.y - a.y) * (a.x - b.x) - (a.y - b.y) * (c.x - a.x);
double D = (d.y - a.y) * (a.x - b.x) - (a.y - b.y) * (d.x - a.x);
if(C * D > 0) return false;
return true;
}
bool check(point a , point b , point c , point d)
{
if(!line_make_point(a , b , c , d)) return false;
if(!line_make_point(c , d , a , b)) return false;
return true;
}
int main()
{
#ifdef DoubleQ
freopen("in.txt","r",stdin);
#endif
int T;
scanf("%d",&T);
while(T--)
{
struct point a , b , c , d;
a.input();
b.input();
c.input();
d.input();
if(check(a , b , c , d))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
/*************************************************
*
* Copyright By DoubleQ
* Written in 2015
* Blog Address : zhanghe.ac.cn
* http://blog.csdn.net/u013447865
* Email Address: [email protected]
*
*************************************************/