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/ ...
随机推荐
- awk--动作(action)
摘要 在awk--简述中我们讲到awk是由pattern-action组合而成的,关于pattern我们已经awk--模式(pattern)在讲述,接下来就来看下awk的action. 动作是什么 我 ...
- JS~字符串长度判断,超出进行自动截取(支持中文)
今天一个小弟问我的问题,在文本框中输入字符,如果超出指定长度,就把它截取,要求中文等于两个字符的长度,我找一下资料,把这个功能实现了,下面是JS代码: <html> <script ...
- C语言单元測试
C语言单元測试 对于敏捷开发来说,单元測试不可缺少,对于Java开发来说,JUnit非常好,对于C++开发,也有CPPUnit可供使用,而对于传统的C语言开发,就没有非常好的工具可供使用,能够找到的有 ...
- struts2,hibernate,spring整合笔记(2)
上一话struts2,hibernate,spring整合笔记(1) 接下来继续 配置完struts之后就要开始hibernate的配置 hibernate的环境并不依赖web开发环境,在我第一次配置 ...
- 《C专家编程》第一天
1.2 C语言的早期体验 1)C语言的基本数据类型直接与底层硬件相对应.C语言不存在内置的复数类型.C语言一开始不支持浮点类型,直到硬件系统能够直接支持浮点数之后才增加了对它的支持. 2)auto关键 ...
- Sqlserver查询表结构信息-字段说明、类型、长度等信息
Sqlserver 中查询表结构信息-字段说明.类型.长度等信息综合语法. SELECT 表名 = d.name,--case when a.colorder=1 then d.name else ' ...
- android使用微软EWS发送邮件
通常我们在android使用javamail发送邮件,可是很多时候我们需要连接Exchange服务(很多公司内部邮件服务器采用,并且未开通smtp服务)来发送邮件,这时候我们就要用到微软的 ews-j ...
- 检查主机是否存活的shell脚本
#!/bin/bash PREFIX= num= " ]; do echo -en "Pinging ${PREFIX}.${num}..." >& &qu ...
- nginx 根据IP 进行灰度发布
灰度发布,简单来说,就是根据各种条件,让一部分用户使用旧版本,另一部分用户使用新版本. nginx 的语法本身可以看作是一门小型的编程语言,通过简单的编程,可以轻松实现基于IP的灰度发布. 需求:搭建 ...
- c - 统计字符串"字母,空格,数字,其他字符"的个数和行数.
#include <stdio.h> #include <ctype.h> using namespace std; /* 题目:输入一行字符,分别统计出其中英文字母.空格.数 ...