1410

来源:互联网 发布:淘宝在线人数免费插件 编辑:程序博客网 时间:2024/06/11 19:55
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;const double EPS = 1e-8;struct point{double x, y;void set(const double xx, const double yy){x = xx;y = yy;}};struct line{point head, rear;void set(const double x1, const double y1, const double x2, const double y2){head.set(x1, y1);rear.set(x2, y2);}};struct rectangle{point tl, dr;void adjust(){if(tl.x > dr.x){if(tl.y > dr.y){swap(tl.x, dr.x);}else{swap(tl, dr);}}else{if(tl.y < dr.y){swap(tl.y, dr.y);}}}};inline bool is_point_in_rec(const point &p, const rectangle &rec){return ((p.x - rec.tl.x) * (p.x - rec.dr.x) <= 0) && ((p.y - rec.tl.y) * (p.y - rec.dr.y) <= 0);}inline double multi(const double x1, const double y1, const double x2, const double y2){return x1 * y2 - x2 * y1;}inline int cross(const point &p, const line &l){const double product = multi(p.x - l.head.x, p.y - l.head.y, l.rear.x - l.head.x, l.rear.y - l.head.y);if(abs(product) < EPS){return 0;}return (product < 0)? -1: 1;}inline bool mutex(const line &l1, const line &l2){const double xminl1 = min(l1.head.x, l1.rear.x);const double xmaxl1 = max(l1.head.x, l1.rear.x);const double yminl1 = min(l1.head.y, l1.rear.y);const double ymaxl1 = max(l1.head.y, l1.rear.y);const double xminl2 = min(l2.head.x, l2.rear.x);const double xmaxl2 = max(l2.head.x, l2.rear.x);const double yminl2 = min(l2.head.y, l2.rear.y);const double ymaxl2 = max(l2.head.y, l2.rear.y);return (abs(xminl1 - xmaxl2) < EPS || xminl1 < xmaxl2) &&(abs(xminl2 - xmaxl1) < EPS || xminl2 < xmaxl1) &&(abs(yminl1 - ymaxl2) < EPS || yminl1 < ymaxl2) &&(abs(yminl2 - ymaxl1) < EPS || yminl2 < ymaxl1);}inline bool line_cross(const line &l1, const line &l2){if(!mutex(l1, l2)){return false;}if(cross(l1.head, l2) * cross(l1.rear, l2) <= 0 && cross(l2.head, l1) * cross(l2.rear, l1) <= 0){return true;}return false;}int main(){int n;line seg, left, down, right, up;rectangle rec;scanf("%d", &n);for(int i = 0; i < n; ++i){scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &seg.head.x, &seg.head.y, &seg.rear.x, &seg.rear.y, &rec.tl.x, &rec.tl.y, &rec.dr.x, &rec.dr.y);rec.adjust();if(is_point_in_rec(seg.head, rec) || is_point_in_rec(seg.rear, rec)){printf("T\n");continue;}left.set(rec.tl.x, rec.tl.y, rec.tl.x, rec.dr.y);down.set(rec.tl.x, rec.dr.y, rec.dr.x, rec.dr.y);right.set(rec.dr.x, rec.dr.y, rec.dr.x, rec.tl.y);up.set(rec.dr.x, rec.tl.y, rec.tl.x, rec.tl.y);if(line_cross(seg, left) || line_cross(seg, down) || line_cross(seg, right) || line_cross(seg, up)){printf("T\n");}else{printf("F\n");}}return 0;}