link
題意:詢問是否存在直線,使得所有線段在其上的投影擁有公共點
思路:如果投影擁有公共區域,那麼從投影的公共區域作垂線,顯然能夠與所有線段相交,那麼題目轉換為詢問是否存在直線與所有線段相交。判斷相交先求叉積再用跨立實驗。列舉每個線段的起始結束點作為直線起點終點遍歷即可。
/** @date : 2017-07-12 14:35:44* @filename: poj 3304 基礎線段交判斷.cpp
* @platform: windows
* @author : lweleth ([email protected])
* @link :
* @version : $id$
*/#include #include #include #include #include #include #include #include #include #include #include #include //#include #define ll long long
#define pii pair#define mp(x, y) make_pair((x),(y))
#define fi first
#define se second
#define pb(x) push_back((x))
#define mmg(x) memset((x), -1,sizeof(x))
#define mmf(x) memset((x),0,sizeof(x))
#define mmi(x) memset((x), inf, sizeof(x))
using namespace std;
const int inf = 0x3f3f3f3f;
const int n = 1e5+20;
const double eps = 1e-8;
struct point
point(){}
point operator -(const point &b) const
double operator *(const point &b) const
double operator ^(const point &b) const
};
struct line
line(point ss, point tt)
};double cross(point a, point b)
double xmult(point p1, point p2, point p0)
double distc(point a, point b)
bool opposite(point p1, point p2, line l)
//線段與線段交
bool sjudgeinter(line a, line b)
int sign(double x)
//線段與直線交 a為直線
bool judgeinter(line a, line b)
int n;
point p[200];
line l[200];
bool check(line li)
int main()
int ans = 0;
/*for(int i = 0; i < n * 2; i++)//不知道為啥直接列舉所有點就是wa
}if(!flag)
ans = 1;
cout << i << "~"<< j << endl;
}}*/
for(int i = 0; i < n; i++)
}} printf("%s\n", ans?"yes!":"no!");
} return 0;
}//詢問是否存在直線,使得所有線段在其上的投影擁有公共點
//如果存在公共區域,對其作垂線,那麼其垂線必定過所有的線段
//那麼轉換為是否存在直線 與所有線段都相交
POJ 3304 Segments(計算幾何)
description 給出n條線段,問是否存在一條直線與這n條線段的任一條都相交 input 第一行一整數t表示用例組數,每組用例首先輸入一整數n表示線段數量,之後n行每行四個實數x1,y1,x2,y2分別表示線段兩端點橫縱座標 output 對於每組用例,如果存在一條直線與這n條線段的任一條都相...
poj3304 Segments 計算幾何
poj 3304 最近開始刷計算幾何了 公式好多完全不會 數學不行 幾何不行 記憶力不行 當機 查的題解 就當複習吧 這套專題拿來熟悉一下計算幾何模板 include include includeusing namespace std const double eps 1e 8 int sgn d...
POJ 3304 Segments 簡單幾何
題目大意 給出n條線段,現在問是否存在一條直線,使得所有線段向這條直線的投影存在乙個共同的交點 題目分析 題意有點抽象,需要轉換一下,因為所有的線段向某一條直線的投影存在乙個交點,那麼在那條直線上,從交點位置開始,沿著垂直於直線的方向做另一條直線,會發現這條直線與n條線段都存在乙個交點,也就是都相交...