问题 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的更多相关文章

  1. POJ 1584 A Round Peg in a Ground Hole 判断凸多边形 点到线段距离 点在多边形内

    首先判断是不是凸多边形 然后判断圆是否在凸多边形内 不知道给出的点是顺时针还是逆时针,所以用判断是否在多边形内的模板,不用是否在凸多边形内的模板 POJ 1584 A Round Peg in a G ...

  2. 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 ...

  3. POJ - 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)

    http://poj.org/problem?id=1584 题意 按照顺时针或逆时针方向输入一个n边形的顶点坐标集,先判断这个n边形是否为凸包. 再给定一个圆形(圆心坐标和半径),判断这个圆是否完全 ...

  4. Peter and Snow Blower CodeForces - 613A (点到线段距离)

    大意: 给定多边形, 给定点$P$, 求一个以$P$为圆心的最小的圆环包含整个多边形. #include <iostream> #include <cmath> #define ...

  5. HDU 6697 Closest Pair of Segments(线段距离)

    首先最容易想到的就是N2暴力枚举所有线段去找最小值,但是这样会做了许多无用功.我们可以先对线段排序,使得线段最左侧的端点按照x轴y轴排序,然后我们可以限定在这个线段的矩形框内的所有线段才有可能产生最小 ...

  6. (点到线段的最短距离)51nod1298 圆与三角形

    1298 圆与三角形 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交.相交输出"Yes",否则输出"No".(三角形的面积大于0).   收起 ...

  7. poj1584(判断凸包+求点到线段的距离)

    题目链接:https://vjudge.net/problem/POJ-1584 题意:首先要判断凸包,然后判断圆是否在多边形中. 思路: 判断凸包利用叉积,判断圆在多边形首先要判断圆心是否在多边形中 ...

  8. UVa 11168 (凸包+点到直线距离) Airport

    题意: 平面上有n个点,求一条直线使得所有点都在直线的同一侧.并求这些点到直线的距离之和的最小值. 分析: 只要直线不穿过凸包,就满足第一个条件.要使距离和最小,那直线一定在凸包的边上.所以求出凸包以 ...

  9. 诡异之--map clear 之后可能导致size != 0的操作

    map<char, int>mp; charMp[; charMp['b'] ++; cout<<charMp['a']<<endl; cout<<ch ...

随机推荐

  1. [C#]浮点数除零无法捕获异常的解决办法

    解决方法: //运算前先检查被除数是否为零,为零则手动抛出除零异常 if (numberB == 0.0) { throw new DivideByZeroException(); } Result ...

  2. JS正则表达式从入门到入土(4)—— 预定义类与边界

    预定义类 正则表达式提供预定义类来匹配常见的字符类 字符 等价类 含义 . [^\r\n] 除了回车符和换行符以外的所有字符 \d [0-9] 数字字符 \D [^0-9] 非数字字符 \s [\t\ ...

  3. Web前端学习笔记之JavaScript、jQuery、AJAX、JSON的区别

    官网的英文解释: javascript和jQuery有点关系,js是一种脚本语言,主要用于客户端,现在主要用于实现一些网页效果. jquery是js的一个库,你可以认为是对js的补充,提供了很多方便易 ...

  4. Nginx将不同IP的请求分发到不同的WEB服务器

    server { listen ; server_name localhost; large_client_header_buffers 16k; client_max_body_size 300m; ...

  5. 【纯代码】Swift - 自定义底部弹窗基类(可根据需要自行扩展内容)

    //弹窗视图 class PopView : UIView { var selectButtonCallBack:((_ title:String)-> Void)? var contenVie ...

  6. [翻译]理解CSS模块方法

    在这个前端发展日新月异的世界,能够找到有所影响的概念相当困难,而将其准确无误的传达,让人们愿意尝试,更是难上加难. 拿CSS来看,在我们写CSS时,工具侧最大的变化,也就是CSS处理器的使用,如:可能 ...

  7. 混合开发的大趋势之一React Native之页面跳转(2)+物理返回+特定平台代码

    转载请注明出处:这里写链接内容 今天是10月份的最后一天,我加了3个月来的第一个班,挤出了这篇. 废话不多先安利,然后继续学习 RN 有好东西都往里面丢,努力做好归纳 https://github.c ...

  8. class文件直接修改_反编译修改class文件变量

    今天笔者同事遇到一个问题,客户同事的数据库连接信息直接写在代码中,连接的密码改了,但是又没有源代码,所以只能直接修改Java class文件. 记录一下修改步骤: 1.下载JClassLib_wind ...

  9. 前端打印功能实现及css设置

    首先是使用下边代码,实现js局部打印功能.参数dom为需要打印的节点,为了保证页面功能的单一性,最好弹出一个新的预览页面完成打印功能. function print(dom){ var body = ...

  10. html5本地存储之localstorage 、本地数据库、sessionStorage简单使用示例

    这篇文章主要介绍了html5本地存储的localstorage .本地数据库.sessionStorage简单使用示例,需要的朋友可以参考下 html5的一个非常cool的功能,就是web stora ...