NEU 1496 Planar map 计算几何,点到线段距离 难度:0
问题 H: Planar map
时间限制: 1 Sec 内存限制: 128 MB
提交: 24 解决: 22
[提交][状态][讨论版]
题目描述
Tigher has work for a long time in a famous company.One day she is given a planar map(look at
the following) and a point.The planar map can be regarded as a polygon.The planar map has n
positions,which are the n vertexes in the polygon.
Actually the point replace the position of a supermarket.The supermarket has a range of its
effect,which show as a circle.The company wants to know the maximum radius of the
circle.Unfortunately,Tigher decides to see movie with her BF this evening.So she give the project
to the ipqhjjybj(so poor!).However,ipqhjjybj want to have dinner with his new friends(do you
remember the “hengheng eat noodles” last time),so he throw the project to you.Can you solve it?
输入
An interger CASE ,which means the total case num.
For every case, the first line is an interger means n.(1<=n<=6)
Then will be n lines (x , y) which indicates the n points' position.
The n+2 line will be the coordinate of the supermarket,and we promise that this point must be in the internal of the planar map.
And this n points will form n lines , which is (n1, n2) (n2 , n3) (n3 ,n4) (n4, n5)...(nn,n1)
输出
It will give just an real number . (Preserve 3 decimal places)
样例输入
4
4
0 0
2 0
2 2
0 2
1 1
1
1 1
1 1
6
0 0
2 0
3 1
2 2
1 1
0 2
1 0.5
3
0 0
0 1
1 0
0.5 0.5
样例输出
1.000
0.000
0.500
0.000
提示
对所有线段取点到线段距离最小值
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct pnt{
double x,y;
pnt(){x=y=0;}
pnt(double x,double y){this->x=x;this->y=y;}
};
pnt pt[100];
int n;
double caldis(pnt a,pnt b){return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));}
double calc(pnt o,pnt a,pnt b){
if(a.y==b.y){
if(o.x<=max(a.x,b.x)&&o.x>=min(a.x,b.x))return fabs(o.y-a.y);
else return min(caldis(o,a),caldis(o,b));
}
else if(a.x==b.x){
if(o.y<=max(a.y,b.y)&&o.y>=min(a.y,b.y))return fabs(o.x-a.x);
else return min(caldis(o,a),caldis(o,b));
}
else{
double k=(b.y-a.y)/(b.x-a.x);
double tx=o.y-a.y+k*a.x+o.x/k;
tx/=(k+1/k);
double ty=k*(tx-a.x)+a.y;
if(tx<=max(a.x,b.x)&&tx>=min(a.x,b.x)&&ty<=max(a.y,b.y)&&ty>=min(a.y,b.y)){
return caldis(o,pnt(tx,ty));
}
else return min(caldis(o,a),caldis(o,b));
}
}
int main(){
int T;
scanf("%d",&T);
for(int ti=0;ti<T;ti++){
scanf("%d",&n);
pnt o;
for(int i=0;i<n;i++){
scanf("%lf%lf",&pt[i].x,&pt[i].y);
}
scanf("%lf%lf",&o.x,&o.y);
double ans=1e19;
for(int i=0;i<n;i++){
ans=min(ans,calc(o,pt[i],pt[(i+1)%n]));
}
printf("%.3f\n",ans);
}
return 0;
}
NEU 1496 Planar map 计算几何,点到线段距离 难度:0的更多相关文章
- POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内
首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...
- POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4438 Acc ...
- POJ - 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
http://poj.org/problem?id=1584 题意 按照顺时针或逆时针方向输入一个n边形的顶点坐标集,先判断这个n边形是否为凸包. 再给定一个圆形(圆心坐标和半径),判断这个圆是否完全 ...
- Peter and Snow Blower CodeForces - 613A (点到线段距离)
大意: 给定多边形, 给定点$P$, 求一个以$P$为圆心的最小的圆环包含整个多边形. #include <iostream> #include <cmath> #define ...
- HDU 6697 Closest Pair of Segments(线段距离)
首先最容易想到的就是N2暴力枚举所有线段去找最小值,但是这样会做了许多无用功.我们可以先对线段排序,使得线段最左侧的端点按照x轴y轴排序,然后我们可以限定在这个线段的矩形框内的所有线段才有可能产生最小 ...
- (点到线段的最短距离)51nod1298 圆与三角形
1298 圆与三角形 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交.相交输出"Yes",否则输出"No".(三角形的面积大于0). 收起 ...
- poj1584(判断凸包+求点到线段的距离)
题目链接:https://vjudge.net/problem/POJ-1584 题意:首先要判断凸包,然后判断圆是否在多边形中. 思路: 判断凸包利用叉积,判断圆在多边形首先要判断圆心是否在多边形中 ...
- UVa 11168 (凸包+点到直线距离) Airport
题意: 平面上有n个点,求一条直线使得所有点都在直线的同一侧.并求这些点到直线的距离之和的最小值. 分析: 只要直线不穿过凸包,就满足第一个条件.要使距离和最小,那直线一定在凸包的边上.所以求出凸包以 ...
- 诡异之--map clear 之后可能导致size != 0的操作
map<char, int>mp; charMp[; charMp['b'] ++; cout<<charMp['a']<<endl; cout<<ch ...
随机推荐
- PreparedStatement和Statement区别详解
技术原理 该 PreparedStatement接口继承Statement,并与之在两方面有所不同: PreparedStatement 实例包含已编译的 SQL 语句.这就是使语句“准备好”.包含于 ...
- 自我管理--拖延 vs 心理
案例1:你在销售公司产品,需要更多客户,这时你收到一条短信,说对你们产品感兴趣,让你马上发送详细资料看看,语气颇为傲慢.你有点恼火,这个人一点都不客气,于是两小时后你才发送过去. 案例2:这个月的 ...
- 照着官网来安装openstack pike之environment设置
安装openstack前的准备环境: 两个centos7系统的环境:192.168.101.10 node1,192.168.101.11 node2 控制节点node1,计算节点node2 1.统一 ...
- 20144303 《Java程序设计》第四周学习总结
20144303 <Java程序设计>第四周学习总结 教材学习内容总结 继承(extends): 1.作用:提高代码复用性 让类与类产生了关系,有了这个关系才有了多态的特性 2.注意:千万 ...
- 20145231熊梓宏《网络对抗》逆向及Bof基础
20145231网络对抗<逆向及Bof基础> 实验目的与要求 1.本次实践的对象是一个名为pwn1的linux可执行文件. 2.若该程序正常执行,则main函数会调用foo函数,foo函数 ...
- HDFS的回收站 && 安全模式
回收站机制 1). HDFS 的回收站机制由 core-site.xml 中 fs.trash.interval 属性(以分钟为单位)设置,默认是 0,表示未启用.注意:配置数值应该为1440,而配置 ...
- 从零开始玩转JMX(三)——Model MBean
Model MBean 相对于Standard MBean,Model MBean更加灵活.如果我们不能修改已有的Java类,那么使用Model MBean是不错的选择. Model MBean也是一 ...
- HTTP协议Keep-Alive模式详解和HTTP头字段总结
1.什么是Keep-Alive模式? 我们知道HTTP协议采用“请求-应答”模式,当使用普通模式,即非KeepAlive模式时,每个请求/应答客户和服务器都要新建一个连接,完成 之后立即断开连接(HT ...
- HTTP协议中的COOKIE机制简单理解
1.为什么会有COOKIE这种机制 首先一种场景, 在一个网站上面, 我发起一次请求,那服务器怎么知道我是谁?是谁发起的这次请求呢, HTTP协议是无状态的协议, 浏览器的每一次请求,服务器都当做一次 ...
- 百度云如何免费扩容至2055G?
百度云如何免费扩容至2055G? 上篇说到整一个新的百度账号,那么5G的百度云内存肯定满足不了我们收集癖的需求.那么就来了解一下怎么扩容吧. 主要是在手机端实现的 用这个新的百度账号在手机APP上登录 ...