那些年不想寫的計算幾何,總有一天要還。
直接列舉點,列舉四邊形即可,只要用叉乘判斷點是否在兩條線段中間即可。
o (n
m)
o(nm)
o(nm
)
#include
#include
#include
#include
#include
using
namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define n 5010
#define eps 1e-8
inline
intsgn
(double x)
inline
double
my_sqrt
(double x)
inline
double
sqr(
double x)
struct point
inline
double
norm()
const
inline
double
norm2()
const
inline point unit()
const
inline point negate()
const
inline point rot90()
const
//counter_clockwise
inline point _rot90()
const
//clockwise
inline point rotate
(double theta)
const
intget()
void
out()}
;inline
bool
operator==(
const point &a,
const point &b)
inline
bool
operator!=(
const point &a,
const point &b)
inline
bool
operator
<
(const point &a,
const point &b)
inline point operator+(
const point &a,
const point &b)
inline point operator-(
const point &a,
const point &b)
inline point operator*(
const point &a,
const
double
&b)inline point operator/(
const point &a,
const
double
&b)inline
double
det(
const point &a,
const point &b)
inline
double
dot(
const point &a,
const point &b)
inline
double
dis(
const point &a,
const point &b)
struct line
inline
double
length()
const
}li[n]
;//線段交點
//注意如果兩條線段是共線的且有交點,那麼intersect_judgement確實會返回true
//但是line_intersect會求錯,所以這種情況需要特判
inline
bool
point_on_segment
(const point &a,
const line &b)
inline
bool
two_side
(const point &a,
const point &b,
const line &c)
inline
bool
intersect_judgement
(const line &a,
const line &b)
inline point line_intersect
(const line &a,
const line &b)
inline
double
point_to_line
(const point &a,
const line &b)
point project_to_line
(const point &a,
const line &b)
inline
double
point_to_segment
(const point &a,
const line &b)
bool
in_polygon
(const point &p,
const vector
&poly)
return counter!=0;
}struct circle};
inline
bool
operator==(
const circle &a,
const circle &b)
inline
bool
operator!=(
const circle &a,
const circle &b)
inline
bool
in_circle
(const point &p,
const circle &c)
point circumcenter
(const point &a,
const point &b,
const point &c)
//圓的生成函式
circle make_circle
(const point &a,
const point &b)
circle make_circle
(const point &a,
const point &b,
const point &c)
//直線與圓的交點
//返回ab方向的第乙個交點
point line_circle_intersect
(const line &l,
const circle &c)
//圓與圓的交點
point circle_intersect
(const circle &a,
const circle &b)
//點到圓的切線
pair
tangent
(const point &p,
const circle &c)
int n,m,ans[n]
;inline
bool
check
(const point &p,
const line &a,
const line &b)
intmain()
while
(m--)if
(x==x2)
for(
int i=
0;i<=n;
++i)}}
for(
int i=
0;i<=n;
++i)
printf
("%d: %d\n"
,i,ans[i]);
puts(""
);}return0;
}
POJ 2318 TOYS(計算幾何)
description 乙個矩形區域中有n條互不相交的線段,每條線段的上下端點分別在矩形的上下邊上,現給出該矩形區域中m個點的座標,保證點不在邊上,統計由這n條邊將矩形分成的n 1個區域中各有多少個點 input 多組用例,每組用例第一行六個整數n,m,xl,yl,xr,yr分別表示邊數,點數,矩形...
POJ 2318 TOYS 計算幾何
點我看題 題意 用n個分隔板把乙個矩形分成n 1個部分,然後有m個點分布在這個矩形上,問每個區域上能有多少個點。分析 利用叉乘和二分解題。首先預處理出這些分隔板,然後對每個點進行二分,二分條件是看當前要判斷的點在隔板的左還是右,而利用叉乘正好可以判斷點在左還是右邊。include include i...
POJ 2318 TOYS(計算幾何入門)
題意 題意就是給你一連串的四邊形區域,再給你一些點,讓你判斷每個四邊形內 包括邊界有多少個點。很簡單的題目,用叉積就能判斷點和直線的關係。created by cqu cst wuerli include include include include include include include...