#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=1e4;
struct point
{
long long x,y;
point(int a=0,int b=0):x(a),y(b) {}
} ;
point p[2*maxn+50];
const int dx[6]= {-1,-1,0,1,1,0};
const int dy[6]= {0,1,1,0,-1,-1};
int n,m,num=0;
void make(int d,int l)
{
// cout<<num<<endl;
while(l--)
p[++num]=point(p[num-1].x+dx[d], p[num-1].y+dy[d]);
}
void prepare()
{
p[2]=point(1,-1);
num=2;
for(int i=1; i<=60; i++)
{
for(int j=0; j<4; j++)
make(j,i);
make(4,i+1);
make(5,i);
}
}
int main()
{
prepare();
while(scanf("%d%d",&n,&m)==2&&(n+m))
{
long long ans;
long long x=p[n].x-p[m].x;
long long y=p[n].y-p[m].y;
if(x*y>0) ans=abs(x+y);
else ans=max(abs(x),abs(y));
printf("The distance between cells %d and %d is %lld.\n",n,m,ans);
}
return 0;
}
题目地址: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=749
UVA 808(p342)----Bee Breeding
最新推荐文章于 2020-02-15 17:01:51 发布