poj-1807-Bee Breeding-坐标系

2014-11-24 09:03:08 · 作者: · 浏览: 0

建立坐标系。

然后根据点的坐标来判断两点之间的距离。

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        using namespace std; #define LL int vector
       
        vecx,vecy; void add(int x,int y){vecx.push_back(x);vecy.push_back(y);} LL xx[8]={-1,0,1,1,0}; LL yy[8]={1,2,1,-1,-2}; void init() { int i,j,k; LL x,y; vecx.clear(); vecy.clear(); x=y=0; add(x,y); y-=2; add(x,y); for(i=1;i<=1000;i++) { for(j=0;j<5;j++) { for(k=1;k<=i;k++) { x+=xx[j]; y+=yy[j]; add(x,y); } } y-=2; add(x,y); for(k=1;k<=i;k++) { x-=1; y-=1; add(x,y); } } } int maps[1001][1001]; int main() { init(); int n,m; while(~scanf("%d%d",&n,&m)&&(n||m)) { n--; m--; LL tx=vecx[n]-vecx[m]; LL ty=vecy[n]-vecy[m]; if(tx<0)tx=-tx; if(ty<0)ty=-ty; int ans=0; if(tx>ty)ans=tx; else ans=tx+(ty-tx)/2; printf("The distance between cells %d and %d is %d.\n",n+1,m+1,ans); } return 0; }