题意:

      求点到圆,然后在到矩形的最短路.

思路:

      把圆切成两半,然后对于每一半这个答案都是凸性的,最后输出两半中小的那个就行了,其中有一点,就是求点到矩形的距离,点到矩形的距离就是点到矩形四条边距离中最小的哪一个,求的方法有很多,一开始想都没想直接敲了个三分(这样就是两重三分了)跑了890ms AC的,后来看了看人家的都是直接用模板过的,我也找了个模板,结果31ms AC,哎,没事真的多暂歇模板,只有好处没坏处是了..


#include<stdio.h>
#include<math.h>
#include<algorithm> #define eps 1e-3
double PI=acos(-1.0); using namespace std; typedef struct
{
double
x ,y;
}
NODE; typedef struct
{

NODE A ,B;
}
EDGE; NODE node[10];
EDGE edge[10];
NODE S ,O;
double
diss1[10] ,diss2[10];
double
R; bool camp(NODE a ,NODE b)
{
return
a.x < b.x || a.x == b.x && a.y < b.y;
} double
dis(NODE a ,NODE b)
{
double
tmp = pow(a.x - b.x ,2.0) + pow(a.y - b.y ,2.0);
return
sqrt(tmp);
} double
minn(double x ,double y)
{
return
x < y ? x : y;
} double
abss(double x)
{
return
x > 0 ? x : -x;
}
NODE getnode(double du)
{

NODE ans;
ans.x = O.x + R *cos(du);
ans.y = O.y + R * sin(du);
return
ans;
}
//**********************************
struct Point
{
double
x,y;
Point(double xx=0,double yy=0):x(xx),y(yy){}
Point operator -(const Point p1)
{
return
Point(x-p1.x,y-p1.y);
}
double operator ^(const
Point p1)
{
return
x*p1.x+y*p1.y;
}
};
double
cross(Point a,Point b)
{
return
a.x*b.y-a.y*b.x;
}
inline int
sign(double d)
{
if(
d>eps)return 1;
else if(
d<-eps)return -1;
else return
0;
}
double
dis(Point A ,Point B)
{
return
sqrt(pow(A.x - B.x ,2.0) + pow(A.y - B.y ,2.0));
}
double
ptoline(Point tp,Point st,Point ed)//求点到线段的距离
{
double
t1=dis(tp,st);
double
t2=dis(tp,ed);
double
ans=min(t1,t2);
if(
sign((ed-st)^(tp-st))>=0 && sign((st-ed)^(tp-ed))>=0)//锐角
{
double
h=fabs(cross(st-tp,ed-tp))/dis(st,ed);
ans=min(ans,h);
}
return
ans;
}

//************************
double search3_2(double L ,double R)
{
double
low ,up ,mid ,mmid;
NODE now;
low = L ,up = R;
while(
1)
{

mid = (low + up) / 2;
now = getnode(mid);
Point A ,B ,C;
A.x = now.x ,A.y = now.y;
for(int
i = 1 ;i <= 4 ;i ++)
{

B.x = edge[i].B.x ,B.y = edge[i].B.y;
C.x = edge[i].A.x ,C.y = edge[i].A.y;
diss1[i] = ptoline(A ,B ,C) + dis(S ,now); }
sort(diss1 + 1 ,diss1 + 4 + 1);
mmid = (mid + up) / 2;
now = getnode(mmid); A.x = now.x ,A.y = now.y;
for(int
i = 1 ;i <= 4 ;i ++)
{

B.x = edge[i].B.x ,B.y = edge[i].B.y;
C.x = edge[i].A.x ,C.y = edge[i].A.y;
diss2[i] = ptoline(A ,B ,C) + dis(S ,now);
}

sort(diss2 + 1 ,diss2 + 4 + 1);
if(
diss1[1] > diss2[1]) low = mid;
else
up = mmid;
if(
abss(low - up) < eps) break;
}
return
diss1[1];
} int main ()
{
while(~
scanf("%lf %lf" ,&S.x ,&S.y))
{
if(
S.x == 0 && S.y == 0) break;
scanf("%lf %lf %lf" ,&O.x ,&O.y ,&R);
scanf("%lf %lf %lf %lf" ,&node[1].x ,&node[1].y ,&node[2].x ,&node[2].y);
node[3].x = node[1].x ,node[3].y = node[2].y;
node[4].x = node[2].x ,node[4].y = node[1].y;
sort(node + 1 ,node + 4 + 1 ,camp);
edge[1].A.x = node[1].x ,edge[1].A.y = node[1].y;
edge[1].B.x = node[2].x ,edge[1].B.y = node[2].y;
edge[2].A.x = node[2].x ,edge[2].A.y = node[2].y;
edge[2].B.x = node[4].x ,edge[2].B.y = node[4].y;
edge[3].A.x = node[4].x ,edge[3].A.y = node[4].y;
edge[3].B.x = node[3].x ,edge[3].B.y = node[3].y;
edge[4].A.x = node[3].x ,edge[4].A.y = node[3].y;
edge[4].B.x = node[1].x ,edge[4].B.y = node[1].y;
printf("%.2lf\n" ,minn(search3_2(0 ,PI) ,search3_2(PI ,2*PI)));
}
return
0;
}

hdu4454 三分 求点到圆,然后在到矩形的最短路的更多相关文章

  1. hihocoder 1142 三分求极值【三分算法 模板应用】

    #1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一 ...

  2. Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交

    题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...

  3. Hihocoder #1142 : 三分·三分求极值

    1142 : 三分·三分求极值 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 这一次我们就简单一点了,题目在此: 在直角坐标系中有一条抛物线y=ax^2+bx+c和一个 ...

  4. Python 求点到直线的垂足

    Python 求点到直线的垂足 在已知一个点,和一条已知两个点的直线的情况下 运算公式参考链接:https://www.cnblogs.com/mazhenyu/p/3508735.html def ...

  5. POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

    题目链接: POJ:http://poj.org/problem? id=2546 ZOJ:problemId=597" target="_blank">http: ...

  6. hdu 1174:爆头(计算几何,三维叉积求点到线的距离)

    爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  7. HLJU 1221: 高考签到题 (三分求极值)

    1221: 高考签到题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 9  Solved: 4 [Submit][id=1221">St ...

  8. HDU 4355——Party All the Time——————【三分求最小和】

    Party All the Time Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. ZOJ 3203 Light Bulb( 三分求极值 )

    链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L ...

随机推荐

  1. POJ-2240(floyd算法简单应用)

    Arbitrage poj-2240 #include<iostream> #include<cstdio> #include<cstring> #include& ...

  2. 测试平台系列(2) 给Pity添加配置

    给Pity添加配置 回顾 还记得上篇文章创立的「Flask」实例吗?我们通过这个实例,给根路由 「/」 绑定了一个方法,从而使得用户访问不同路由的时候可以执行不同的方法. 配置 要知道,在一个「Web ...

  3. 爬虫入门到放弃系列05:从程序模块设计到代理IP池

    前言 上篇文章吧啦吧啦讲了一些有的没的,现在还是回到主题写点技术相关的.本篇文章作为基础爬虫知识的最后一篇,将以爬虫程序的模块设计来完结. 在我漫(liang)长(nian)的爬虫开发生涯中,我通常将 ...

  4. 一篇看懂JVM底层详解,利用class反编译文件了解文件执行流程

    JVM之内存结构详解 JVM内存结构 java虚拟机在执行程序的过程中会将内存划分为不同的区域,具体如图1-1所示. 五个区域 JVM分为五个区域:堆.虚拟机栈.本地方法栈.方法区(元空间).程序计数 ...

  5. Codeforces Round #538 D. Lunar New Year and a Wander

    题面: 传送门 题目描述: Bob想在公园散步.公园由n个点和m条无向边组成.当Bob到一个未经过的点时,他就会把这个点的编号记录在笔记本上.当且仅当Bob走完所有的点,他才会停下来.这时,Bob的笔 ...

  6. imagemagick 之 Fred's ImageMagick Scripts 在Ubuntu 下的实践

    Fred's ImageMagick Scripts 官网:http://www.fmwconcepts.com/imagemagick/index.php Windows 10 (64-bit) u ...

  7. Django之Auth认证模块

    一.Auth模块是什么 Auth模块是Django自带的用户认证模块: 我们在开发网站的时候,无可避免的需要设计实现网站的用户系统,此时我们需要实现包括用户注册,用户登陆,用户认证,注销修改密码等功能 ...

  8. css字体的属性

    1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...

  9. java例题_37 有 n 个人围成一圈,顺序排号。从第一个人开始报数(从 1 到 3 报数),凡报到 3 的人退出圈子, 3 问最后留下的是原来第几号的那位。

    1 /*37 [程序 37 报数] 2 题目:有 n 个人围成一圈,顺序排号.从第一个人开始报数(从 1 到 3 报数),凡报到 3 的人退出圈子, 3 问最后留下的是原来第几号的那位. 4 */ 5 ...

  10. 人多力量大vs.两个披萨原则,聊聊持续交付中的流水线模式

    人多力量大vs.两个披萨原则,聊聊持续交付中的流水线模式 在前面5期文章中,我们分别详细介绍了持续交付体系基础层面的建设,主要是多环境和配置管理,这些是持续交付自动化体系的基础,是跟我们实际的业务场景 ...