Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9733 | Accepted: 2566 |
Description
Input
Output
Sample Input
1 4 9 11 2 1 5 7 1
Sample Output
F
Source
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <cmath> using namespace std; const double eps = 1e-8; struct point { int x; int y; }; struct line { point start; point endx; }; int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0 ? -1 : 1; } double det(const point p1, const point p2, const point p0) { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } bool PointOnSegment(const line a, point p) { if((dcmp(det(a.start, a.endx, p))==0) && ((a.start.x-p.x)*(a.endx.x-p.x)+(a.start.y-p.y)*(a.endx.y-p.y))<=0) return true; return false; } bool Point_in_rectangle(int x1, int x2, int y1, int y2, line a) { if((a.start.x>=x1 && a.start.x <=x2 && a.start.y>=y1 && a.start.y<=y2)&& a.endx.x>=x1 && a.endx.x<=x2 && a.endx.y>=y1 && a.endx.y<=y2) return true; return false; } bool ok(const line a, const line b) { int flag1 = 0, flag2 = 0; if(max(a.start.x, a.endx.x)>=min(b.start.x, b.endx.x) && max(b.start.x, b.endx.x)>=min(a.start.x, a.endx.x) && max(a.start.y, a.endx.y)>=min(b.start.y, b.endx.y) && max(b.start.y, b.endx.y)>=min(a.start.y, a.endx.y) && det(b.start, a.endx, a.start)*det(a.endx, b.endx,a.start)> 0 && det(a.start, b.endx, b.start)*det(b.endx, a.endx, b.start)> 0 ) flag1 = 1; if(PointOnSegment(a, b.endx)||PointOnSegment(a, b.start) ||PointOnSegment(b, a.endx) || PointOnSegment(b, a.start) ) flag2 = 1; if(flag1 || flag2) return true; return false; } int main() { //freopen("d:\\in.txt","r",stdin); //freopen("d:\\out.txt","w",stdout); int n; int xstart, ystart, xend, yend; int xleft, ytop, xright, ybottom; line a, b, c, d; line t; bool flag = false; scanf("%d", &n); int tmp1, tmp2, tmp3, tmp4; while(n--) { flag = false; scanf("%d%d%d%d", &xstart, &ystart, &xend, ¥d); scanf("%d%d%d%d", &xleft, &ytop, &xright, &ybottom); t.start.x = xstart; t.start.y = ystart; t.endx.x = xend; t.endx.y = yend; tmp1 = min(xleft, xright); tmp2 = max(xleft, xright); tmp3 = min(ytop, ybottom); tmp4 = max(ytop, ybottom); a.start.x = a.endx.x = c.start.x = b.endx.x = tmp1; //xleft; a.start.y = b.start.y = b.endx.y = d.endx.y = tmp4;//ytop; a.endx.y = d.start.y = c.start.y = c.endx.y = tmp3;//ybottom; b.start.x = c.endx.x = d.start.x = d.endx.x = tmp2;//xright; if(Point_in_rectangle(tmp1, tmp2, tmp3, tmp4, t)) flag = true; if(ok(a,t)) flag = true; if(ok(b,t)) flag = true; if(ok(c,t)) flag = true; if(ok(d,t)) flag = true; if(flag){ printf("T\n"); } else { printf("F\n"); } } return 0; }