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 ;
}
上一篇:Node.js博客搭建


下一篇:想要做自动化测试?八款高 Star 开源测试工具分享