description
給出n條線段,問是否存在一條直線與這n條線段的任一條都相交
input
第一行一整數t表示用例組數,每組用例首先輸入一整數n表示線段數量,之後n行每行四個實數x1,y1,x2,y2分別表示線段兩端點橫縱座標
output
對於每組用例,如果存在一條直線與這n條線段的任一條都相交則輸出yes!,否則輸出no!
sample input
3 2
1.0 2.0 3.0 4.0
4.0 5.0 6.0 7.0
3 0.0 0.0 0.0 1.0
0.0 1.0 0.0 2.0
1.0 1.0 2.0 1.0
3 0.0 0.0 0.0 1.0
0.0 2.0 0.0 3.0
1.0 1.0 2.0 1.0
sample output
yes!
yes!
no!
solution
如果存在一條合法直線與任一條線段都相交,那麼通過適當的旋轉一定能讓這條直線經過2n個端點中的某兩個,所以只需要c(2n,2)的列舉兩個端點判斷過這兩點的直線是否合法即可
code
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using
namespace
std;
typedef
long
long ll;
#define inf 0x3f3f3f3f
#define maxn 111
#define eps 1e-8
struct point
point(double _x,double _y)
point operator -(const point &b)const
double
operator ^(const point &b)const
double
operator *(const point &b)const
};struct line
line(point _s,point _e)
};double dis(point a,point b)
//判斷x的符號
int sgn(double x)
//判斷線段相交
bool inter(line l1,line l2)
int t,n;
point p[2*maxn];
line l[maxn];
int main()
int flag=0;
for(int i=1;i<=2*n&&!flag;i++)
for(int j=i+1;j<=2*n&&!flag;j++)
if(flag)break;
}printf("%s\n",flag?"yes!":"no!");
}return
0;}
poj3304 Segments 計算幾何
poj 3304 最近開始刷計算幾何了 公式好多完全不會 數學不行 幾何不行 記憶力不行 當機 查的題解 就當複習吧 這套專題拿來熟悉一下計算幾何模板 include include includeusing namespace std const double eps 1e 8 int sgn d...
POJ 3304 Segments 簡單幾何
題目大意 給出n條線段,現在問是否存在一條直線,使得所有線段向這條直線的投影存在乙個共同的交點 題目分析 題意有點抽象,需要轉換一下,因為所有的線段向某一條直線的投影存在乙個交點,那麼在那條直線上,從交點位置開始,沿著垂直於直線的方向做另一條直線,會發現這條直線與n條線段都存在乙個交點,也就是都相交...
POJ 3304 Segments 基礎線段交判斷
link 題意 詢問是否存在直線,使得所有線段在其上的投影擁有公共點 思路 如果投影擁有公共區域,那麼從投影的公共區域作垂線,顯然能夠與所有線段相交,那麼題目轉換為詢問是否存在直線與所有線段相交。判斷相交先求叉積再用跨立實驗。列舉每個線段的起始結束點作為直線起點終點遍歷即可。date 2017 07...