#include <cstdio>#include <cmath>#include <algorithm>usingnamespacestd;
constdoubleEPS=1e-6;
constdoubleSQRT3=sqrt((double)3);
constintdir[7][2] = {{0, 0}, {-1, 1}, {0, 2}, {1, 1}, {1, -1}, {0, -2}, {-1, -1}};
structPoint{
doublex, y;
};
doubler, xa, ya, xb, yb;
doublestepx, stepy;
boolinput();
PointfindFirstSection(doublex, doubley);
Pointfind(doublex, doubley);
voidsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
}
return0;
}
boolinput()
{
if (scanf("%lf%lf%lf%lf%lf", &r, &xa, &ya, &xb, &yb) !=5||!(r||xa||ya||xb||yb)) returnfalse;
stepx=1.5*r;
stepy=SQRT3/2*r;
returntrue;
}
PointfindFirstSection(doublex, doubley)
{
intdx= (int)(x/stepx);
intdy= (int)(y/stepy);
if (dx&1) {
if (!(dy&1)) dy++;
} else {
if (dy&1) dx++;
}
doubleMin=0x3f3f3f3f;
Pointans;
for (inti=0; i<7; i++) {
doubletmpx=stepx* (dx+dir[i][0]);
doubletmpy=stepy* (dy+dir[i][1]);
doubletmp=sqrt(pow(tmpx-x, 2) +pow(tmpy-y, 2));
if (tmp<Min) {
ans.x=tmpx;
ans.y=tmpy;
Min=tmp;
}
}
returnans;
}
Pointfind(doublex, doubley)
{
Pointans;
if (x>0&&y>0) {
ans=findFirstSection(x, y);
} elseif (x<0&&y>0) {
ans=findFirstSection(-x, y);
ans.x=-ans.x;
} elseif (x<0&&y<0) {
ans=findFirstSection(-x, -y);
ans.x=-ans.x;
ans.y=-ans.y;
} else {
ans=findFirstSection(x, -y);
ans.y=-ans.y;
}
returnans;
}
voidsolve()
{
Pointa=find(xa, ya);
Pointb=find(xb, yb);
doubledis;
if (fabs(a.x-b.x) <EPS&&fabs(a.y-b.y) <EPS) {
dis=sqrt(pow(xa-xb, 2) +pow(ya-yb, 2));
printf("%.3lf\n", dis);
return;
}
intx1= (int)(fabs(a.x-b.x) /stepx+0.5);
intx2= (int)(fabs(a.y-b.y) /stepy+0.5);
intd;
if (x1>=x2) {
d=x1;
} else {
d=x1+ (x2-x1) /2;
}
dis=sqrt(pow(a.x-xa, 2) +pow(a.y-ya, 2)) +sqrt(pow(b.x-xb, 2) +pow(b.y-yb, 2)) +d*SQRT3*r;
printf("%.3lf\n", dis);
}