Codeforces Gym 101505C : Cable Connection (计算几何)
题意:给出第一象限的N个点,存在一直线x/a+y/b=1(a>0,y>0)使得所有点都在这条直线下面,求 min{sqrt(a^2+b^2)}
显然,这样的直线必然经过这N个点中的某一个(可用反证法证得),所以先对只有一个点的情况进行分析。
当只有一个点P(x0,y0)时,易得

此时设t=a/b,可知,a^2+b^2可写成两个凹函数相加的形式,故可用三分法求解。
所以N个点的情况就可解了。容易想到,只需要考虑凸包上位于右上侧的点(满足该点的左上方右下方都有点),那么该点就有成为“关键的点”的可能,至于三分时的自变量的范围,就根据这个点的前后两个点来得到即可。
#include<bits/stdc++.h>
using namespace std; const double eps=1e-;
const double inf=2e6;
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<? -:;
} struct Point
{
double x,y;
Point(double x_=,double y_=)
{
x=x_,y=y_;
}
Point operator -(const Point& rhs)
{
return Point(x-rhs.x,y-rhs.y);
}
bool operator<(const Point& rhs)const
{
return x<rhs.x||x==rhs.x&&y<rhs.y;
}
};
typedef Point Vector;
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
double Area2(Point A,Point B,Point C)
{
return Cross(B-A,C-A);
}
int ConvexHull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for(int i=; i<n; i++)
{
while(m>&&dcmp(Area2(ch[m-],ch[m-],p[i]))<=) --m;
ch[m++]=p[i];
}
int k=m;
for(int i=n-; i>=; --i)
{
while(m>k&&dcmp(Area2(ch[m-],ch[m-],p[i]))<=) --m;
ch[m++]=p[i];
}
return n>? m-:m;
}
//=============================================================
const int maxn=1e6+;
Point p[maxn],ch[maxn];
double k[maxn]; double xielv(Point A,Point B)
{
if(dcmp(A.x-B.x)==) return -inf;
else return (A.y-B.y)/(A.x-B.x);
}
double cal(Point P,double P_k)
{
double a=P.x-P.y/P_k;
double b=P.y-P.x*P_k;
return sqrt(a*a+b*b);
}
double sanfen(Point P,double k1,double k2)
{
double l=k1,r=k2;
while(r-l>eps)
{
double mid=(l+r)/;
double f1=cal(P,mid);
double midmid=(mid+r)/;
double f2=cal(P,midmid);
if(f1<f2) r=midmid;
else l=mid;
}
return cal(P,l);
} int main()
{
int n,m;
while(~scanf("%d",&n))
{
double ans=inf;
double maxx=,maxy=;
for(int i=; i<n; i++) //读点
{
scanf("%lf%lf",&p[i].x,&p[i].y);
maxx=max(maxx,p[i].x),maxy=max(maxy,p[i].y);
}
p[n++]=Point(maxx,),p[n++]=Point(,maxy); //加点,便于处理
m=ConvexHull(p,n,ch); //求凸包
for(int i=; i<m; i++) k[i]=xielv(ch[i],ch[(i+)%m]); //求斜率
for(int i=; i<m; i++)
if(ch[i].x>=ch[(i+)%m].x&&ch[i].y<=ch[(i+)%m].y && ch[(i+)%m].x>=ch[(i+)%m].x&&ch[(i+)%m].y<=ch[(i+)%m].y)
ans=min(ans,sanfen(ch[(i+)%m],k[i],k[(i+)%m]));
printf("%.3lf\n",ans+eps);
}
}
Codeforces Gym 101505C : Cable Connection (计算几何)的更多相关文章
- Codeforces Gym 100338B Geometry Problem 计算几何
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- check cable connection PXE-M0F: Exiting intel PXE ROM no bootable device-- insert boot disk and pre
今天修电脑遇到一个问题,新买的电脑的原装的是linux,然后我按常规方式进入PE后重装系统,然后开机一直显示下面的代码,进不去: check cable connection PXE-M0F: Exi ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】
2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
随机推荐
- JMeter强大的性能测试工具
JMeter强大的性能测试工具,可模拟服务器负载,进行性能测试 配合badboy采集请求数据.
- GoLand远程Linux开发环境搭建
Goland 远程调试本文介绍如何从本机的goland连接远端server上的go代码进行调试 goland下载安装 建议购买正版,科学使用自行搜索. 需要安装插件,确保可以访问官网,不然配置下pro ...
- 《Google工作法》读书笔记
最近一段时间,拜读了<Google工作法>,工作效率提升10倍的57个技巧. 作者是彼得·费利克斯·格日瓦奇,波兰人. 其中印象最深刻的部分如下: (1)不要被邮件夺走时间 不用邮件,所有 ...
- upd通讯Recvfrom设置阻塞不起作用
把自己踩到的坑记录一下,在做UDP通讯的时候,发现自己的程序没有收数据居然也有百分之十二的cpu占用率,通过性能分析工具了解到时recvfrom函数一直在执行,虽然设置阻塞并且确认成功了, ;//阻塞 ...
- XSS-反射型
前情提要:html的dom对象:document 如document.cookie / document.write() http://netsecurity.51cto.com/art/20131 ...
- mysql——多表——外连接查询——左连接、右连接、复合条件查询
), d_id ), name ), age ), sex ), homeadd ) ); ,,,'nan','beijing'); ,,,'nv','hunan'); ,,,'nan','jiang ...
- axios中设置Content-Type不生效的问题
Api:axios(config): config中无data字段时,headers里的Content-Type无效果,这应该出于优化的层面,此时的Content-Length=0,无需向服务端提供C ...
- tp5后台同步更新配置文件
thinkphp5 配置文件路径:app/extra/web.php public function add(){ $path = 'app/extra/web.php'; $file = inclu ...
- python-day13(正式学习)
闭包函数 闭包 闭包:闭是封闭(函数内部函数),包是包含(该内部函数对外部作用域而非全局作用域的变量的引用).闭包指的是:函数内部函数对外部作用域而非全局作用域的引用. 额...这里提示一下闭包!=自 ...
- Ubuntu下更新Pycharm时权限不够(PyCharm does not have write access to...)
问题描述 更新Pycharm时,出现如下问题 PyCharm does not have write access to /usr/local/software/pycharm-2019.1.3. P ...