poj 1410
题目不难,就是线段相交判断。叉积和点积的应用,但是却需要细心,看清题意
#include <iostream> #include <stdio.h> using namespace std; int cross(int x1,int y1,int x2,int y2) { return x1*y2-y1*x2; } int dot(int x1,int y1,int x2,int y2) { return x1*x2+y1*y2; } int ons(int x1,int y1,int x2,int y2,int x3,int y3) { if(cross(x3-x1,y3-y1,x3-x2,y3-y2)==0&&dot(x3-x1,y3-y1,x3-x2,y3-y2)<=0) return 1; else return 0; } int judge(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4) { int c1=cross(x2-x1,y2-y1,x3-x1,y3-y1),c2=cross(x2-x1,y2-y1,x4-x1,y4-y1), c3=cross(x4-x3,y4-y3,x1-x3,y1-y3),c4=cross(x4-x3,y4-y3,x2-x3,y2-y3); if(c1*c2<0&&c3*c4<=0) return 1; else if(c1*c2==0&&(ons(x1,y1,x2,y2,x3,y3)||ons(x1,y1,x2,y2,x4,y4))) return 1; return 0; } int main() { int sx,sy,ex,ey,xleft,ytop,xright,ybottom; int n; scanf("%d",&n); while(n--) { scanf("%d%d%d%d%d%d%d%d",&sx,&sy,&ex,&ey,&xleft,&ytop,&xright,&ybottom); int minx=min(xleft,xright),maxx=max(xleft,xright); int miny=min(ytop,ybottom),maxy=max(ytop,ybottom); int flag=0; if((ex>=minx&&ex<=maxx&&sx>=minx&&sx<=maxx&&sy>=miny&&sy<=maxy&&ey>=miny&&ey<=maxy)||judge(sx,sy,ex,ey,xleft,ytop,xright,ytop)||judge(sx,sy,ex,ey,xleft,ytop,xleft,ybottom) ||judge(sx,sy,ex,ey,xleft,ybottom,xright,ybottom)||judge(sx,sy,ex,ey,xright,ybottom,xright,ytop)) flag=1; if(flag) printf("T\n"); else printf("F\n"); } return 0; }