bzoj4948: World Final2017 A
求简单多边形内的最长线段长度
显然存在一组最优解,使其所在直线经过多边形的两个端点,枚举这两个端点,求出直线和多边形的有效交点,从而得出直线有哪些部分在多边形内(含边界)。
由于多边形的一些边可能与直线重合,求交需要一些分类讨论。
#include<bits/stdc++.h>
typedef long long i64;
typedef double ld;
struct pos{
int x,y;
ld abs(){return sqrt(i64(x)*x+i64(y)*y);}
}ps[];
pos operator-(const pos&a,const pos&b){return (pos){a.x-b.x,a.y-b.y};}
i64 operator*(const pos&a,const pos&b){return i64(a.x)*b.y-i64(a.y)*b.x;}
int sgn(i64 x){return x<?-:x>;}
int n,t[],kp;
ld ans=,ks[];
void maxs(ld&x,ld y){if(x<y)x=y;}
#define F(a) ps[a]*ps[a+1]/ld(p*(ps[a+1]-ps[a]))*pl
void chk(pos p){
kp=;
ld pl=p.abs();
for(int i=;i<n+;++i)t[i]=sgn(p*ps[i]);
for(int i=,z;i<n;++i)if(t[i]&&t[i]!=t[i+]){
for(z=i+;!t[z];++z);
if(t[z]!=t[i]){
if(z-i<)ks[kp++]=F(i);
else{
ld a0=F(i),a1=F(z-);
ks[kp++]=(a0<a1)==(t[i]>)?a0:a1;
}
}else if(z-i==){
ld a0=F(i),a1=F(z-);
if((a0<a1)==(t[i]>))maxs(ans,fabs(a1-a0));
}
}
std::sort(ks,ks+kp);
for(int i=;i<kp;i+=)maxs(ans,ks[i+]-ks[i]);
}
int main(){
scanf("%d",&n);
for(int i=;i<n;++i)scanf("%d%d",&ps[i].x,&ps[i].y);
for(int i=;i<n;++i){
pos o=ps[i];
for(int j=;j<n;++j)ps[j]=ps[j]-o;
for(int j=;j<;++j)ps[n+j]=ps[j];
for(int j=i+;j<n;++j)chk(ps[j]);
}
printf("%.8f",ans);
return ;
}
bzoj4948: World Final2017 A的更多相关文章
随机推荐
- js学习:return arguments
return函数 arguments
- CentOS7.0防火墙以及开关机命令
CentOS 7.0默认使用的是firewall作为防火墙 查看防火墙状态firewall-cmd --state 停止firewallsystemctl stop firewalld.service ...
- 【牛客练习赛22 C】
https://www.nowcoder.com/acm/contest/132/C 题目大意:在n个区间中取出n个数,相加的和一共会出现多少种结果. 题目分析:对于这种挑选数字相加,由于每一步不同的 ...
- windows server 2008 R2 部署NFS,实现多台服务器间、客户端间的共享目录。
如何通过Windows Server 2008 R2建立NFS存储服务? 通过Windows Server 2008 R2,我们可以很容易地将其作为一台NFS存储服务器,得到一个NFS软存储,轻松解决 ...
- 找DEV,欢迎挑战高薪 --方向:互联网金融,地点广州
http://kaolalicai.cn/#/join 企业文化 加入财略 = 进取!自由!快乐 Get things done,坚持,进取 学习型企业,员工培训,交互学习 人性化管理,气氛和谐,快乐 ...
- Python知识点整理,基础3 - 字典操作
- Centos7安装32位库用来安装32位软件程序
打算在centos7上安装一个远程控制软件,发现teamviewer只有centos的32位版本,试着安装了一下,各种报错,尝试多次无果.于是试着用向日葵远程控制软件,也报错,貌似也是只支持32位. ...
- MySQL Network--Localhost与127.0.0.1的差异
localhost为本地服务器,而127.0.01为本机地址.在使用localhost时不经过网卡传输,不受网络防火墙和网卡相关的限制,访问localhost不会被解析成ip地址,不会占用网卡和网络资 ...
- ClusterControl 强大免费数据管理工具
几张参考图 galera 集群管理 多种数据库管理 组件架构 参考资料 https://severalnines.com/docs/intro.html
- 100 webhook implementations
转自: https://streamdata.io/blog/100-webhook-implementations/ 很不错的整理 What is the scope of the event-d ...