daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define f(i,x,y) for (int i = x; i < y; i++)
  3. #define fd(i,x,y) for(int i = x; i>= y; i--)
  4. #define FOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
  5. #define all(v) (v).begin(), (v).end()
  6. #define rall(v) (v).rbegin(), (v).rend()
  7. #define vint vector<int>
  8. #define ll long long
  9. #define clr(A,x) memset(A, x, sizeof A)
  10. #define pb push_back
  11. #define pii pair<int,int>
  12. #define fst first
  13. #define snd second
  14. #define ones(x) __builtin_popcount(x)
  15. #define cua(x) (x)*(x)
  16. #define eps (1e-9)
  17. #define oo (1<<30)
  18. #define debug(x) cout <<#x << " = " << x << endl
  19. #define adebug(x,n) cout <<#x<<endl; f(i,0,n)cout<<x[i]<<char(i+1==n?10:32)
  20. #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)
  21. #define N 1
  22. using namespace std;
  23.  
  24. struct punto{
  25.     ll x,y;
  26.     punto(ll x, ll y): x(x), y(y) {}
  27.     punto() {}
  28.     punto operator+(punto p) { return punto(x+p.x, y+p.y); }
  29.     punto operator-(punto p) { return punto(x-p.x, y-p.y); }
  30.     ll operator*(punto p) { return x*p.x + y*p.y; }
  31.     ll operator%(punto p) { return x*p.y - y*p.x; }
  32.     punto operator~() { return punto(-y, x); }
  33.     void read() { scanf("%lld%lld", &x, &y); }
  34. };
  35.  
  36. bool entre01(ll x, ll y) { // x/y
  37.     if(y < 0) x = -x, y = -y;
  38.     return 0 <= x && x <= y;
  39. }
  40.  
  41. bool inter(punto a, punto b, punto c, punto d) {
  42.     if ((b-a) % (d-c) == 0) {
  43.         if ((b-a) % (c-a) == 0) {
  44.             ll ta = 0, tb = (b-a)*(b-a), tc = (c-a)*(b-a), td = (d-a)*(b-a);
  45.             if (tb < tc || td < ta) return 0;
  46.             return 1;
  47.         } else return 0;
  48.     }
  49.     return entre01((c-a) % (d-c), (b-a) % (d-c))
  50.         && entre01((a-c) % (b-a), (d-c) % (b-a));
  51. }
  52.  
  53. int main(){
  54.     int t; cin >> t;
  55.     while (t--) {
  56.         punto a, b;
  57.         ll x1,x2,y1,y2;
  58.         a.read();
  59.         b.read();
  60.         scanf("%lld%lld%lld%lld", &x1, &y2, &x2, &y1);
  61.         if (x1 > x2) swap(x1,x2);
  62.         if (y1 > y2) swap(y1,y2);
  63.         punto p[5];
  64.         p[0] = punto(x1,y1);
  65.         p[1] = punto(x1,y2);
  66.         p[2] = punto(x2,y2);
  67.         p[3] = punto(x2,y1);
  68.         p[4] = p[0];
  69.         bool ok = 0;
  70.         f(i,0,4) if (inter(p[i], p[i+1], a, b)) ok = 1;
  71.         if (x1 <= a.x && a.x <= x2 && y1 <= a.y && a.y <= y2) ok = 1;
  72.         if (x1 <= b.x && b.x <= x2 && y1 <= b.y && b.y <= y2) ok = 1;
  73.         puts(ok? "T" : "F");
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top