ural 1348 Goat in the Garden 2
http://acm.timus.ru/problem.aspx?space=1&num=1348
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1e-; double dcmp(double x){
if(fabs(x)<eps) return ;
else return x<?-:;
} double sqr(double x)
{
return x*x;
}
struct node
{
double x,y;
}st3,st1,st2; double cross(node a,node b)
{
return (a.x*b.y-a.y*b.x);
}
double dot(node a,node b)
{
return (a.x*b.x+a.y*b.y);
}
double dis(double x1,double y1,double x2,double y2)
{
return sqrt(sqr(x1-x2)+sqr(y1-y2));
} double distance1(node p,node a,node b)
{
if(a.x==b.x&&a.y==b.y) return dis(p.x,p.y,a.x,a.y);
node p1; p1.x=b.x-a.x;p1.y=b.y-a.y;
node p2; p2.x=p.x-a.x;p2.y=p.y-a.y;
node p3; p3.x=p.x-b.x;p3.y=p.y-b.y;
if(dcmp(dot(p1,p2))<) return dis(p.x,p.y,a.x,a.y);
else if(dcmp(dot(p1,p3))>) return dis(p.x,p.y,b.x,b.y);
else return (fabs(cross(p1,p2))/dis(a.x,a.y,b.x,b.y));
} int main()
{
double x1,y1,x2,y2,x3,y3,l;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
scanf("%lf%lf%lf",&x3,&y3,&l);
st1.x=x1;st1.y=y1;
st2.x=x2;st2.y=y2;
st3.x=x3;st3.y=y3;
double l1=dis(st3.x,st3.y,st1.x,st1.y);
double l2=dis(st3.x,st3.y,st2.x,st2.y);
double l3=distance1(st3,st1,st2);
double min1=min(l1,min(l2,l3));
double max1=max(l1,max(l2,l3));
double ans1=min1-l;
double ans2=max1-l;
if(ans1<eps) ans1=;
if(ans2<eps) ans2=;
printf("%.2lf\n",ans1);
printf("%.2lf\n",ans2);
return ;
}
ural 1348 Goat in the Garden 2的更多相关文章
- sgu 1348 Goat in the Garden 2【点到线段的距离】
链接: http://acm.timus.ru/problem.aspx?space=1&num=1348 http://acm.hust.edu.cn/vjudge/contest/view ...
- ural 1084 Goat in the Garden
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> u ...
- POJ 1518 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 1584 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest
Solved A Gym 100488A Yet Another Goat in the Garden B Gym 100488B Impossible to Guess Solved C Gym ...
- ural 2064. Caterpillars
2064. Caterpillars Time limit: 3.0 secondMemory limit: 64 MB Young gardener didn’t visit his garden ...
- HDU5977 Garden of Eden(树的点分治)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5977 Description When God made the first man, he ...
- hdu-5977 Garden of Eden(树分治)
题目链接: Garden of Eden Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
随机推荐
- CXF框架入门实例
首先:什么是CXF?为什么要用CXF? CXF 包含了大量的功能特性,但是主要集中在以下几个方面:支持 Web Services 标准:CXF 支持多种 Web Services 标准,包含 SOAP ...
- SpringMVC整合fastjson-1.1.41
以前用fastjson也只是硬编码,就好像这篇博文写的http://blog.csdn.net/jadyer/article/details/24395015 昨天心血来潮突然想和SpringMVC整 ...
- Android布局属性详解剖析
View的布局显示方式有下面几种: 线性布局(LinearLayout) 相对布局(RelativeLayout) 表格布局(TableLayout) 网格视图(GridView) 标签布局(TabL ...
- js中的for...in循环机制
1) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.o ...
- Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
遇着这个提示的话,如果本地只安装了一个mysql,这里写的很详细的 http://www.blogjava.net/asenyifei/articles/82575.html 看这里可以解决,如果本地 ...
- 综合使用LruCache和DiskLruCache 缓存图片
Activity public class MainActivity extends Activity { private GridView mPhotoWall; private P ...
- 数据库 SQL 外键约束 多表查询
多表设计与多表查询 1.外键约束 表是用来保存现实生活中的数据的,而现实生活中数据和数据之间往往具有一定的关系,我们在使用表来存储数据时,可以明确的声明表和表之前的依赖关系,命令数据库来 ...
- ImageView的学习
学习安卓时我还是习惯看懂手册,虽然是英文但是可以获得的东西必然也是更多的,否则自己只能停留在拾人牙缝的水平,虽然我是初学,但是还是分享一些自己的学习过程及方法. 从手册中我们看以知道,ImageVie ...
- 修复 status 为 unusable 的 index
以DBA权限登陆,执行以下脚本即可. declare -- 指向所有 UNUSABLE 状态的 index 的游标 cursor c is select index_n ...
- iOS实现OAuth2.0中刷新access token并重新请求数据操作
一.简要概述 OAuth2.0是OAuth协议的下一版本,时常用于移动客户端的开发,是一种比较安全的机制.在OAuth 2.0中,server将发行一个短有效期的access token和长生命期的r ...