题解 多边形

传送门

  • 每天一个坑人小技巧:
    - 是不一样的,前者虽然用鼠标选中时看起来是一个字符,但实际上是三个
    包括快读和 \(\tt cin\) 在内的一切读入方法都会因此寄掉
    此问题可能出现在从 PDF 中复制样例的过程当中
    image
    upd:这玩意是连字符
  • atan2(double a, double y) 返回值为弧度,取值范围 \((-\pi, \pi]\)
    在平面直角坐标系中,结果为正表示从 \(x\) 轴逆时针旋转的角度,结果为负表示从 \(x\) 轴顺时针旋转的角度

显然可以二分答案
发现多边形要在满足到原点距离 \(\geqslant mid\) 的条件下尽量小以使尽量多点在其外部
所以这个多边形与以原点为中心,半径为 \(mid\) 的圆相切
然后转化一下一个点在多边形外部的条件:
考虑过这个点做圆的切线,若多边形存在至少一条边与圆的切点在两个切点间的劣弧上,则这个点在多边形外
那么问题变为 check 用 \(m\) 个点能否覆盖所有给定区间
枚举断点断环为链后倍增 check 即可
复杂度 \(O(n\log n\log\epsilon)\)

  • \(n\) 的划分数的估计值为 \(e^{\sqrt\frac{20n}{3}}\)。格式好奇怪,根号在指数上
点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 200010
#define fir first
#define sec second
#define ll long long
const double pi=acos(-1.0);
//#define int long long

char buf[1<<21], *p1=buf, *p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1<<21, stdin)), p1==p2?EOF:*p1++)
inline int read() {
	int ans=0, f=1; char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-f; c=getchar();}
	while (isdigit(c)) {ans=(ans<<3)+(ans<<1)+(c^48); c=getchar();}
	return ans*f;
}

int n, m;
int lg[N], nxt[21][N], top;
pair<double, double> sta[N];
struct point{double angle, dis;}p[N];

bool check(double mid) {
	top=0;
	for (int i=1; i<=n; ++i) {
		// cout<<"i: "<<i<<endl;
		double tem=acos(mid/p[i].dis);
		if (p[i].angle-tem<-pi) p[i].angle+=2*pi;
		sta[++top]={p[i].angle-tem, p[i].angle+tem};
		sta[++top]={p[i].angle-tem+2*pi, p[i].angle+tem+2*pi};
		// cout<<"add: ("<<p[i].angle-tem<<','<<p[i].angle+tem<<")"<<endl;
		// cout<<"add: ("<<p[i].angle-tem+pi<<','<<p[i].angle+tem+pi<<")"<<endl;
	}
	sort(sta+1, sta+top+1);
	// cout<<"sta: "; for (int i=1; i<=top; ++i) cout<<"("<<sta[i].fir<<','<<sta[i].sec<<") "; cout<<endl;
	for (int i=top,lst=top; i; --i) {
		while (sta[lst-1].fir>sta[i].sec) --lst;
		nxt[0][i]=lst;
		for (int j=1; (top-i+1)>=1<<j; ++j)
			nxt[j][i]=nxt[j-1][nxt[j-1][i]];
	}
	for (int i=1; i<=n; ++i) {
		int pos=i, step=min(m, top-i+1);
		for (int j=lg[step]-1; ~j; --j) if (step>=1<<j)
			pos=nxt[j][pos], step-=1<<j;
		if (!pos || pos>=i+n) return 1;
	}
	return 0;
}

signed main()
{
	freopen("polygon.in", "r", stdin);
	freopen("polygon.out", "w", stdout);

	n=read(); m=read();
	double l=0, r=1e10, mid;
	for (int i=1; i<=n; ++i) {
		ll x=read(), y=read();
		// cout<<x<<' '<<y<<endl;
		p[i]={atan2(y, x), sqrt(x*x+y*y)};
		r=min(r, p[i].dis);
		// cout<<"ang: "<<p[i].angle<<endl;
	}
	for (int i=1; i<=m; ++i) lg[i]=lg[i-1]+(1<<lg[i-1]==i);
	for (int i=1; i<=50; ++i) {
		mid=(l+r)/2;
		if (check(mid)) l=mid;
		else r=mid;
	}
	printf("%.10lf\n", l);
	
	return 0;
}
posted @ 2022-07-07 10:00  Administrator-09  阅读(5)  评论(0编辑  收藏  举报