标签:des style blog http color os strong io
http://poj.org/problem?id=1410
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 11329 | Accepted: 2978 |
Description
Input
Output
Sample Input
1 4 9 11 2 1 5 7 1
Sample Output
F
Source
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #include <math.h> using namespace std; typedef struct point { int x,y; }point; typedef struct line { point st,ed; }line; int crossProduct(point a,point b,point c) { return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); } bool onSegment(point a,point b,point c) { int maxx=max(a.x,b.x); int maxy=max(a.y,b.y); int minx=min(a.x,b.x); int miny=min(a.y,b.y); if(crossProduct(a,b,c)==0&&(c.x<=maxx)&&(c.x>=minx)&&(c.y<=maxy)&&(c.y>=miny)) { return true; } return false; } bool segIntersect(point p1,point p2,point p3,point p4) { int d1=crossProduct(p3,p4,p1); int d2=crossProduct(p3,p4,p2); int d3=crossProduct(p1,p2,p3); int d4=crossProduct(p1,p2,p4); if(d1*d2<0 && d3*d4<0) return true; if(d1==0 && onSegment(p3,p4,p1)) return true; if(d2==0 && onSegment(p3,p4,p2)) return true; if(d3==0 && onSegment(p1,p2,p3)) return true; if(d4==0 && onSegment(p1,p2,p4)) return true; return false; } point p[5]; line li[5]; int num[1005]; int main() { int n,m,i,j; line tmp; int xleft,ytop,xright,ybottom; scanf("%d",&n); while(n--) { scanf("%d%d%d%d%d%d%d%d",&tmp.st.x,&tmp.st.y,&tmp.ed.x,&tmp.ed.y ,&xleft,&ytop,&xright,&ybottom); li[0].st.x=xleft; li[0].st.y=ytop; li[0].ed.x=xleft; li[0].ed.y=ybottom; li[1].st.x=xleft; li[1].st.y=ybottom; li[1].ed.x=xright; li[1].ed.y=ybottom; li[2].st.x=xright; li[2].st.y=ybottom; li[2].ed.x=xright; li[2].ed.y=ytop; li[3].st.x=xright; li[3].st.y=ytop; li[3].ed.x=xleft; li[3].ed.y=ytop; bool flag=true; for(i=0;i<4;i++) { if(segIntersect(tmp.st,tmp.ed,li[i].st,li[i].ed)) { flag=false; break; } } int maxx=max(xleft,xright); int maxy=max(ytop,ybottom); int minx=min(xleft,xright); int miny=min(ytop,ybottom); if(tmp.st.x<=maxx&&tmp.st.x>=minx&&tmp.st.y>=miny&&tmp.st.y<=maxy ||tmp.ed.x<=maxx&&tmp.ed.x>=minx&&tmp.ed.y>=miny&&tmp.ed.y<=maxy) flag=false; if(flag) printf("F\n"); else printf("T\n"); } return 0; }
poj 1410 线段相交判断,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ccccnzb/p/3883547.html