标签:des style blog class code java
Description
Input
Output
Sample Input
1 4 9 11 2 1 5 7 1
Sample Output
F
这个题做得我都快哭了,想了好几天,呜呜呜,,原来矩形的左上和右下的顶点不是按顺序给出,所以还要求最大最小;一开始我还以为先输入直线顶点然后输入矩形顶点,看来我错了,害的我想那么久,效率在哪里??!!
1 /***********************************************************
2 * OS : Win7
3 * Complier : GCC(G++)
4 * All Rights Reserved by GingerZeng.
5 **********************************************************/
6
7 #include<cstdio>
8 #include<cstring>
9 #include<algorithm>
10 #include<cmath>
11 #include<cstdlib>
12 #include<iostream>
13 using namespace std;
14 typedef long long ll;
15 const double eps=0.0000000001;
16 double inter(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy)
17 {
18 if(min(ax,bx)>max(cx,dx)||min(ay,by)>max(cy,dy)||
19 min(cx,dx)>max(ax,bx)||min(cy,dy)>max(ay,by))return false;
20 double h,i,j,k;
21 h=(bx-ax)*(cy-ay)-(by-ay)*(cx-ax);
22 i=(bx-ax)*(dy-ay)-(by-ay)*(dx-ax);
23 j=(dx-cx)*(ay-cy)-(dy-cy)*(ax-cx);
24 k=(dx-cx)*(by-cy)-(dy-cy)*(bx-cx);
25 if(h*i<=eps&&j*k<=eps)return 1.0;
26 else return 0.0;
27 }
28 int main()
29 {
30 int n;
31 //freopen("a.txt","r",stdin);
32 scanf("%d",&n);
33 while(n--)
34 {
35 double xs,ys,xe,ye,xl,yt,xr,yb;
36 scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&xs,&ys,&xe,&ye,&xl,&yt,&xr,&yb);
37 if(min(xs,xe)>=min(xl,xr)&&max(xs,xe)<=max(xl,xr)&&
38 max(ys,ye)<=max(yt,yb)&&min(ys,ye)>=min(yt,yb))printf("T\n");
39 else
40 {
41 double temp1=inter(xs,ys,xe,ye,xl,yt,xr,yt);
42 double temp2=inter(xs,ys,xe,ye,xl,yt,xl,yb);
43 double temp3=inter(xs,ys,xe,ye,xr,yb,xl,yb);
44 double temp4=inter(xs,ys,xe,ye,xr,yt,xr,yb);
45 if(temp1||temp2||temp3||temp4)printf("T\n");
46 else printf("F\n");
47 }
48
49 }
50 return 0;
51 }
poj 1410 Intersection,布布扣,bubuko.com
标签:des style blog class code java
原文地址:http://www.cnblogs.com/GingerZeng/p/3712749.html