Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define f(i,x,y) for (int i = x; i < y; i++)
- #define fd(i,x,y) for(int i = x; i>= y; i--)
- #define FOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
- #define all(v) (v).begin(), (v).end()
- #define rall(v) (v).rbegin(), (v).rend()
- #define vint vector<int>
- #define ll long long
- #define clr(A,x) memset(A, x, sizeof A)
- #define pb push_back
- #define pii pair<int,int>
- #define fst first
- #define snd second
- #define ones(x) __builtin_popcount(x)
- #define cua(x) (x)*(x)
- #define eps (1e-9)
- #define oo (1<<30)
- #define debug(x) cout <<#x << " = " << x << endl
- #define adebug(x,n) cout <<#x<<endl; f(i,0,n)cout<<x[i]<<char(i+1==n?10:32)
- #define mdebug(x,m,n) cout <<#x<<endl; f(i,0,m)f(j,0,n)cout<<x[i][j]<<char(j+1==n?10:32)
- #define N 1
- using namespace std;
- struct punto{
- ll x,y;
- punto(ll x, ll y): x(x), y(y) {}
- punto() {}
- punto operator+(punto p) { return punto(x+p.x, y+p.y); }
- punto operator-(punto p) { return punto(x-p.x, y-p.y); }
- ll operator*(punto p) { return x*p.x + y*p.y; }
- ll operator%(punto p) { return x*p.y - y*p.x; }
- punto operator~() { return punto(-y, x); }
- void read() { scanf("%lld%lld", &x, &y); }
- };
- bool entre01(ll x, ll y) { // x/y
- if(y < 0) x = -x, y = -y;
- return 0 <= x && x <= y;
- }
- bool inter(punto a, punto b, punto c, punto d) {
- if ((b-a) % (d-c) == 0) {
- if ((b-a) % (c-a) == 0) {
- ll ta = 0, tb = (b-a)*(b-a), tc = (c-a)*(b-a), td = (d-a)*(b-a);
- if (tb < tc || td < ta) return 0;
- return 1;
- } else return 0;
- }
- return entre01((c-a) % (d-c), (b-a) % (d-c))
- && entre01((a-c) % (b-a), (d-c) % (b-a));
- }
- int main(){
- int t; cin >> t;
- while (t--) {
- punto a, b;
- ll x1,x2,y1,y2;
- a.read();
- b.read();
- scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1);
- if (x1 > x2) swap(x1,x2);
- if (y1 > y2) swap(y1,y2);
- punto p[5];
- p[0] = punto(x1,y1);
- p[1] = punto(x1,y2);
- p[2] = punto(x2,y2);
- p[3] = punto(x2,y1);
- p[4] = p[0];
- bool ok = 0;
- f(i,0,4) if (inter(p[i], p[i+1], a, b)) ok = 1;
- if (x1 <= a.x && a.x <= x2 && y1 <= a.y && a.y <= y2) ok = 1;
- if (x1 <= b.x && b.x <= x2 && y1 <= b.y && b.y <= y2) ok = 1;
- puts(ok? "T" : "F");
- }
- }
Add Comment
Please, Sign In to add comment