UVA 808 - Bee Breeding(数论+坐标系)
来源:互联网 发布:安卓编程视频 编辑:程序博客网 时间:2024/05/21 19:42
题目链接:808 - Bee Breeding
题意:给定图中蜂窝两点,求最短距离
思路:建坐标系,然后根据图中走的顺序把每个点的坐标求出来,然后利用坐标去求最小距离即可
代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>const int N = 20005;const int d[5][2] = {{-1, 1}, {0, 2}, {1, 1}, {1, -1}, {0, -2}};struct Point {int x, y;Point() {}Point(int _x, int _y) {x = _x; y = _y;}} p[N];int a, b;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++) {int j, k;for (j = 0; j < 5; j++) {for (k = 0; k < i; k++) {x += d[j][0]; y += d[j][1];p[pn++] = Point(x, y);}}y -= 2;p[pn++] = Point(x, y);for (j = 0; j < i; j++) {x--; y--;p[pn++] = Point(x, y);}}}int main() {init();while (~scanf("%d%d", &a, &b) && a || b) {int x = abs(p[a].x - p[b].x);int y = abs(p[a].y - p[b].y);printf("The distance between cells %d and %d is ", a, b);if (y <= x) printf("%d.\n", x);else {printf("%d.\n", x + (y - x) / 2);}}return 0;}
1 0
- UVA 808 - Bee Breeding(数论+坐标系)
- UVA 808Bee Breeding(构造 建立坐标系)
- UVA 808(p342)----Bee Breeding
- uva 808 - Bee Breeding(坐标问题)
- Bee Breeding UVA
- poj-1807-Bee Breeding-坐标系
- pku 1870 bee breeding
- pku1870 Bee Breeding
- POJ 1870 Bee Breeding
- POJ 1870 Bee Breeding
- poj1870 Bee Breeding
- poj1870--Bee Breeding(模拟)
- UVA808 - Bee Breeding
- UVa808 - Bee Breeding(坐标法)
- UVA 10182 - Bee Maja
- UVa, 11000 Bee
- UVA 11000 - Bee
- UVa 1531 - Problem Bee
- 网络爬虫实现原理
- 简单工厂模式、工厂模式、抽象工厂模式的区别
- IPv6常用命令
- IPv6常用命令
- 并发编程实践一:Non-Blocking队列算法
- UVA 808 - Bee Breeding(数论+坐标系)
- 浏览器内核(渲染引擎)
- java的 json解析真蛋疼
- 学习笔记:第3章 数据库基础知识
- 使用hadoop编写日志分析MR程序
- 第7周作业1-循环大战
- mysql高级之日志
- 开源项目之C++界面库 GLUI
- 致逝去acm,程序生涯