太難的比如三維凸包已過濾,估計noi考不了毒瘤計算幾何吧,不過還是背些簡單的吧。
二維凸包:
#includeusingnamespace
std;
struct nodep[10001],q[10001
];int
n,top;
double
ans;
node
operator-(node a,node b);}
double dis(node a,node b)
double cross(node p1,node p2)
bool
cmp(node a,node b)
void
graham()
q[++top]=p[0
];
for(int i=0;i1
]);}
intmain()
旋轉卡殼:
#include#include#include
using
namespace
std;
const
int n=5e4+7
;const
double eps=1e-8
;struct pointp[n],q[n],t[5
];bool
operator
<(point a,point b)
point
operator+(point a,point b);}
point
operator-(point a,point b);}
point
operator*(point a,double b);}
double cross(point a,point b)
double dot(point a,point b)
double dis(point a)
intn,top;
double ans=1e18;
bool
cmp(point a,point b)
void
graham()
q[0]=q[top];
}void
rc()
}}int
main()
半平面交:
#include#include#include
using
namespace
std;
const
int n=1010
;struct pointp[n],a[n];
struct linel[n],q[n];
intn,cnt,tot,top;
double ans=1e18;
point
operator-(point a,point b);}
double
operator*(point a,point b)
bool
operator
<(line a,line b)
point inter(line a,line b);}
bool judge(line a,line b,line c)
void
hpi()
cnt=tot;
q[0]=l[1],q[1]=l[2
];
for(int i=3;i<=cnt;i++)
while(qs1],q[qe],q[qs]))qe--;
while(qs1],q[qs],q[qe]))qs++;
tot=0
;
for(int i=qs;i1
]);}
intmain()
;
if(a[k].x>=p[i].x&&a[k].x<=p[i+1
].x)
ans=min(ans,a[k].y-inter((line),(line)).y);
}for(int k=1;k<=n;k++)
for(int i=1;i)
;if(p[k].x>=a[i].x&&p[k].x<=a[i+1
].x)
ans=min(ans,inter((line),(line)).y-p[k].y);
}printf(
"%.3lf
",ans);
}
凸包的閔可夫斯基和:
#include#define ll long longusing
namespace
std;
const
int n=1e5+9
;struct
point
friend point
operator+(const point&a,const point&b)
friend point
operator-(const point&a,const point&b)
friend ll
operator*(const point &a,const point &b)
ll dis()
}p[n],p1[n],p2[n],t[n],v1[n],v2[n];
bool
cmp(point a,point b)
intn,m,q,top;
int graham(point *p,int
cnt)
for(int i=1;i<=tp;i++)p[i]=t[i];
return
tp;}
void
work()
intinner(point x)
return(p[pos%top+1]-p[pos])*(x-p[pos])>=0;}
intmain()
}
simpson積分:
#include#include#include
#define fabs(x) ((x)>0?(x):-(x))
using
namespace
std;
typedef pair
pii;
const
int n=1007
;const
double pi=acos(-1.0),eps=1e-13,inf=1e100;
struct point;
double dis(point a,point b)
struct
node
pii f(
double
x)
}a[n];
bool
operator
<(node a,node b)
intn,ban[n];
pii p[n];
double f(double
x) sort(p+1,p+cnt+1
);
for(int i=1;i<=cnt;i++)
if(p[i].first>lst)ret+=p[i].second-p[i].first,lst=p[i].second;
else
if(p[i].second>lst)ret+=p[i].second-lst,lst=p[i].second;
return
ret;
}double simpson(double l,double r,double mid,double cl,double cr,double
s)int
main()
掃瞄線當資料結構吧
計算幾何模板整理
整理計算幾何模板,以及一些題目 update 1 基礎函式,點,向量的運算 update 2 凸包,旋轉卡殼 基礎的函式定義 1 const double eps 1e 8 2 int dcmp double x dcmp 基於點和向量的運算 1 struct point 4 point x 0.0...
計算幾何模板
sgn返回x經過eps處理的符號,負數返回 1,正數返回1,x的絕對值如果足夠小,就返回0。const double eps 1e 8 int sgn double x double mysqrt double x pt是point的縮寫 int版 struct pt pt int x,int y ...
計算幾何模板
include define vct point using namespace std const double pi atan2 0,1 const double eps 1e 8 int sgn double d struct point bool operator point b const...