当前位置:网站首页>[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
2022-07-07 02:49:00 【Ouye xjx】
Good questions without links
Title Description
Additional explanation : Although the title refers to convex polygons , But it can not be closed . in other words , You can think of it as m m m Intersection of two half planes . The distance from a point to an edge can be regarded as a line segment , It can also be seen as a straight line , It doesn't matter .
Answer key
We all know the reason why we fall into the category of art students
Why does it matter to regard it as the distance to a line segment or straight line , Because no matter what kind of distance , The distance from each edge to the origin should be equal , Otherwise, it must not be excellent . With this conclusion , We find that the perpendicular line from the origin to the straight line must intersect on the line segment .
First of all, understand that the answer is monotonous , Then you can split the answer . There is another monotonicity , namely m m m The bigger the better .
Consider how to proceed c h e c k \rm check check: First, for a feasible solution , We can rotate each straight line in one direction , Until it hits the point . It is easy to prove that each edge of any feasible solution can always be adjusted to intersect with the point , In this way, the only line to be considered is n n n The article .
Consider a violent practice , We enumerate a straight line as the starting point , Then rotate the scan line , Clockwise each time ( Or counter clockwise ) Greedily find the first satisfaction No node appears in the middle of the two lines As the next line .( Pictured above , Suppose the current line is a a a, that b b b Is the next straight line to find , c c c and d d d Are not )
Until we find m + 1 m+1 m+1 A straight line ( Including the starting point ), Then judge whether the scanning line has swept a circle .
To do it directly is O ( n 2 log ϵ − 1 ) O(n^2\log \epsilon^{-1}) O(n2logϵ−1) Of , So let's preprocess the next line corresponding to each line , Then multiply .
The sum O ( n log n log ϵ − 1 ) O(n\log n\log \epsilon^{-1}) O(nlognlogϵ−1).
Code
#include<bits/stdc++.h>//JZM yyds!!
#define ll long long
#define lll __int128
#define uns unsigned
#define fi first
#define se second
#define IF (it->fi)
#define IS (it->se)
#define END putchar('\n')
#define lowbit(x) ((x)&-(x))
#define inline jzmyyds
using namespace std;
const int MAXN=1e5+5;
const ll INF=1e17;
ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){
if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+(s^48),s=getchar();
return f?x:-x;
}
int ptf[50],lpt;
void print(ll x,char c='\n'){
if(x<0)putchar('-'),x=-x;
ptf[lpt=1]=x%10;
while(x>9)x/=10,ptf[++lpt]=x%10;
while(lpt>0)putchar(ptf[lpt--]^48);
if(c>0)putchar(c);
}
using pdd=pair<double,double>;
const double PI=acos(-1),eps=1e-7;
int n,m,sr[MAXN],k;
pdd tran(const pdd&a){
pdd b;
b.se=sqrt(a.fi*a.fi+a.se*a.se),b.fi=acos(a.fi/b.se);
if(a.se<0)b.fi=PI*2-b.fi;
return b;
}
double dis(const pdd&a,const pdd&b){
pdd c(a.fi-b.fi,a.se-b.se);
return sqrt(c.fi*c.fi+c.se*c.se);
}
pdd pa[MAXN],a[MAXN];
double b[MAXN],ch;
double F(double w){
if(w<0)w+=PI*2;
if(w>PI*2)w-=PI*2;
return min(w,PI*2-w);
}
int jp[MAXN][25];
double jb[MAXN][25];
bool inl(double y,double r,int x){
double ck=F(a[x].fi-y);
return ck*2<PI&&a[x].se*cos(ck)>=r-eps;
}
bool check(const double&r){
for(int i=1;i<=n;i++){
b[i]=a[i].fi+acos(r/a[i].se);
while(b[i]<0)b[i]+=PI*2;
while(b[i]>=PI*2)b[i]-=PI*2;
sr[i]=i;
}
sort(sr+1,sr+1+n,[](int x,int y){
return b[x]<b[y];});
for(int i=1,j=1;i<=n;i++){
int x=sr[i];
if(i==j)j=(j==n?1:j+1);
while(j!=i&&inl(b[x],r,sr[j]))j=(j==n?1:j+1);
jp[i][0]=j,jb[i][0]=b[sr[j]]-b[x];
if(jb[i][0]<eps)jb[i][0]+=PI*2;
}
for(int j=1;j<=18;j++)for(int i=1;i<=n;i++)
jp[i][j]=jp[jp[i][j-1]][j-1],jb[i][j]=jb[i][j-1]+jb[jp[i][j-1]][j-1];
for(int i=1;i<=n;i++){
int x=i;double s=0;
for(int j=18;j>=0;j--)if((m>>j)&1)s+=jb[x][j],x=jp[x][j];
if(s>PI*2-eps)return 1;
}
return 0;
}
const bool PF=0;
int main()
{
freopen("polygon.in","r",stdin);
freopen("polygon.out","w",stdout);
n=read(),m=read(),k=1,ch=INF;
for(int i=1;i<=n;i++){
int x=read(),y=read();
if(x==0&&y==0)return printf("%.9f\n",0.0),0;
a[i]=tran(pa[i]=pdd(x,y)),ch=min(ch,a[i].se);
}
if(m>=n||PF)return printf("%.9f\n",ch),0;
double l=0,r=ch,mid;
for(int NND=30;NND--;){
mid=(l+r)/2;
if(check(mid))l=mid;
else r=mid;
}
printf("%.9f\n",mid);
return 0;
}
边栏推荐
- 数论 --- 快速幂、快速幂求逆元
- Five reasons for clothing enterprises to deploy MES management system
- MySQL提升大量数据查询效率的优化神器
- 实施MES管理系统时,哪些管理点是需要注意的
- 6-6漏洞利用-SSH安全防御
- Qpushbutton- "function refinement"
- Pioneer of Web3: virtual human
- Read fast RCNN in one article
- Redis入门完整教程:复制拓扑
- Have fun | latest progress of "spacecraft program" activities
猜你喜欢
随机推荐
Summary of research status of inertial navigation calibration at home and abroad (abridged version)
The so-called consumer Internet only matches and connects industry information, and does not change the industry itself
QPushButton-》函数精解
Redis入门完整教程:复制原理
fasterxml ToStringSerializerBase报错
Safety delivery engineer
[Mori city] random talk on GIS data (II)
Contribution of Writing Series
C#/VB. Net to delete watermarks in word documents
Use of fiddler
Google Earth engine (GEE) -- 1975 dataset of Landsat global land survey
The panel floating with the mouse in unity can adapt to the size of text content
Niuke programming problem -- double pointer of 101 must be brushed
What are the applications and benefits of MES management system
widerperson数据集转化为YOLO格式
数字滚动增加效果
Convert widerperson dataset to Yolo format
Statistics of radar data in nuscenes data set
1 -- Xintang nuc980 nuc980 porting uboot, starting from external mx25l
QT common Concepts-1