UVA 808Bee Breeding(构造 建立坐标系)

点击打开链接

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=1e5;

int dx[5]={-1,0,1,1,0};
int dy[5]={1,2,1,-1,-2};
struct Point{
	int x;
	int y;
	Point()
	{
	}
	Point(int a,int b)
	{
		x=a;
		y=b;
	}
	
}p[N+20];
void init()
{
	int pn=1,x=0,y=0;;
	p[pn++]=Point(x,y);//按照编号建立坐标 
	y-=2;	
	p[pn++]=Point(x,y);

	for(int i=1;i<=60;i++)//画i个顺时针 
	{	
		for(int j=0;j<5;j++)
		{
			for(int k=1;k<=i;k++)//每个方向画k次 
			{
				x+=dx[j];
				y+=dy[j];
				p[pn++]=Point(x,y);
			}
		}
		y-=2;
		p[pn++]=Point(x,y);//偏移 
	
		for(int j=0;j<i;j++)//回到y轴 
		{
			x--;
			y--;
			p[pn++]=Point(x,y);
			//if(pn<32)
			//cout<<"@"<<pn-1<<" "<<'('<<x<<","<<y<<')'<<endl;
		}
	}
}
int main()
{
	int a,b;
	init();

	while(cin>>a>>b&&a&&b)
	{
		int ans;
		int x=abs(p[a].x-p[b].x);
		int y=abs(p[a].y-p[b].y);
		if(x>=y)//横向差较大 
		ans=x;//斜着走(每步坐标差可以-1)即可(原图中无法横着走) 
		else
		ans=x+(y-x)/2;//斜着走+往上走一步2个单位距离 
		printf("The distance between cells %d and %d is %d.\n",a,b,ans);
	
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值