1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include <bits/stdc++.h> #define Orz ios::sync_with_stdio(0),cin.tie(0) #define rep(i,a,b) for(int i=a;i<=b;i++) #define pii pair<int,int> #define pdd pair<double,double> #define int long long #define ll long long #define ld long double #define N 1003 #define eps 1e-9 #define x first #define y second
using namespace std;
struct pt{ int x,y; bool operator < (pt b){ if(x == b.x)return y < b.y; return x < b.x; } bool operator > (pt b){ if(x == b.x)return y > b.y; return x > b.x; } bool operator == (pt b){ if(x-b.x<=eps && y-b.y<=eps)return true; return false; } pt operator+(pt b) {return {x + b.x, y + b.y};} pt operator-(pt b) {return {x - b.x, y - b.y};} int operator^(pt b) {return x * b.y - y * b.x;} int operator*(pt b) {return x * b.x + y * b.y;} }; vector<pt> point; int dir(pt a, pt b, pt o) { int cross = (a - o) ^ (b - o); if(fabs(cross) <= eps) return 0; else if(cross > 0) return 1; else return -1; } bool onseg(pt a, pt b, pt o){ int cross = (a - o) ^ (b - o); int dot = (a - o) * (b - o); return (cross == 0)&&(dot <= 0); }
bool Intersection(pt a, pt b, pt c, pt d){ if(onseg(a,b,c)||onseg(a,b,d))return true; if(onseg(c,d,a)||onseg(c,d,b))return true; if(dir(a,b,c)*dir(a,b,d)==-1 && dir(c,d,a)*dir(c,d,b)==-1) return true; return false; } int n,t;
void solve(){ point.assign(4,{0,0}); rep(i,0,3)cin>>point[i].x>>point[i].y; if(Intersection(point[0],point[1],point[2],point[3])){ cout<<"Yes"<<endl; } else cout<<"No"<<endl; }
signed main(){ Orz; int t;cin>>t; while(t--){ solve(); } }
|