日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

POJ 1410 Intersection

發布時間:2023/11/27 生活经验 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1410 Intersection 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目大意:

題目意思很簡單,就是說有一個矩陣是實心的,給出一條線段,問線段和矩陣是否相交

An example:?
line: start point: (4,9)?
end point: (11,2)?
rectangle: left-top: (1,5)?
right-bottom: (7,1)?

?

Sample Input

1
4 9 11 2 1 5 7 1

Sample Output

F
題解:
一道鬼題
本身不難,只要拿四條邊與線段做快速排斥和跨立就行
但有很多細節:
1.給出的矩形的坐標要判斷,不合法要交換
2.包含在矩形內,不與任何邊相交
3.與邊共線,還要判斷是否有重合部分
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<cmath>
 6 using namespace std;
 7 struct Node
 8 {
 9     double x1,y1,x2,y2;
10 }line[10001];
11 int T;
12 double xe,ye,xs,ys,xl,yt,xr,yb;
13 double direction(double x,double y,double x1,double y1,double x2,double y2)
14 {  
15     double a1=x1-x;  
16     double b1=y1-y;  
17     double a2=x2-x;  
18     double b2=y2-y;  
19     return a1*b2-a2*b1;  
20 }  
21 int on_segment(double x1,double y1,double x2,double y2,double x,double y)
22 {  
23     if((min(x1,x2)<=x&&x<=max(x1,x2))&&(min(y1,y2)<=y&&y<=max(y1,y2)))  
24         return 1;  
25     return 0;  
26 }  
27   
28 bool exam(Node v,Node t)
29 {  
30     double d1,d2,d3,d4;  
31     d1=direction(t.x1,t.y1,t.x2,t.y2,v.x1,v.y1);  
32     d2=direction(t.x1,t.y1,t.x2,t.y2,v.x2,v.y2);  
33     d3=direction(v.x1,v.y1,v.x2,v.y2,t.x1,t.y1);  
34     d4=direction(v.x1,v.y1,v.x2,v.y2,t.x2,t.y2);  
35     if(d1*d2<0 && d3*d4<0) return 1;  
36     if(!d1&&on_segment(t.x1,t.y1,t.x2,t.y2,v.x1,v.y1)) return 1;  
37     if(!d2&&on_segment(t.x1,t.y1,t.x2,t.y2,v.x2,v.y2)) return 1;  
38     if(!d3&&on_segment(v.x1,v.y1,v.x2,v.y2,t.x1,t.y1)) return 1;  
39     if(!d4&&on_segment(v.x1,v.y1,v.x2,v.y2,t.x2,t.y2)) return 1;  
40     return 0;  
41 }  
42 int main()
43 {
44     cin>>T;
45     while (T--)
46     {
47         scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&xs,&ys,&xe,&ye,&xl,&yt,&xr,&yb);
48      if (yt<yb) swap(yt,yb);
49      if (xl>xr) swap(xl,xr);
50      Node d;
51      d.x1=xs;d.y1=ys;
52      d.x2=xe;d.y2=ye;
53      line[1].x1=xl;line[1].y1=yt;line[1].x2=xr;line[1].y2=yt;
54      line[2].x1=xl;line[2].y1=yb;line[2].x2=xr;line[2].y2=yb;
55      line[3].x1=xl;line[3].y1=yt;line[3].x2=xl;line[3].y2=yb;
56      line[4].x1=xr;line[4].y1=yt;line[4].x2=xr;line[4].y2=yb;
57       if (exam(d,line[1])||exam(d,line[2])||exam(d,line[3])||exam(d,line[4]))
58        {
59            cout<<"T\n";
60        }    
61        else 
62        {
63            if (xl<=min(xs,xe)&&xr>=max(xs,xe)&&yt>=max(ys,ye)&&yb<=min(ys,ye))
64            cout<<"T\n";
65            else 
66            cout<<"F\n";
67        }
68     }
69 }
 

?

?

轉載于:https://www.cnblogs.com/Y-E-T-I/p/7270345.html

總結

以上是生活随笔為你收集整理的POJ 1410 Intersection的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。