http://acm.hdu.edu.cn/showproblem.php?pid=1030

算法:以顶点为原点,建立坐标系,一个数可以唯一对应一个三元组(x, y, z),从任意一个点出发走一步,刚好有三种情况,分别对应x, y, z变化1,而其它两个坐标保持不变。因此,求出两个点的坐标分别为(x1, y1, z1), (x2, y2, z2);则它们之间的距离为|x1 - x2| + |y1 - y2| + |z1 - z2|。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <stack>
#include <string>
#include <ctime>
#include <queue>
#define mem0(a) memset(a, 0, sizeof(a))
#define mem(a, b) memset(a, b, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define eps 0.0000001
#define lowbit(x) ((x) & -(x))
#define memc(a, b) memcpy(a, b, sizeof(b))
#define x_x(a) ((a) * (a))
#define LL long long
#define DB double
#define pi 3.14159265359
#define MD 10000007
#define INF maxNum
#define max(a, b) ((a) > (b)? (a) : (b))
using namespace std;
struct Point {
int x, y, z;
Point(int n) {
int xx = (int)sqrt(n + 0.5);
if(xx * xx < n) xx++;
y = xx;
z = x = y;
int p = (y - ) * (y - );
x -= (n - p) / ;
p = y * y + ;
z -= (p - n) / ;
}
};
int main()
{
//freopen("input.txt", "r", stdin);
int a, b;
while(~scanf("%d%d", &a, &b)) {
Point x(a), y(b);
int ans = abs(x.x - y.x) + abs(x.y - y.y) + abs(x.z - y.z);
printf("%d\n", ans);
}
return ;
}

最新文章

  1. css浮动与绝对定位小记
  2. 24SQL
  3. 六、GAIA
  4. ubuntu 12.04下zmap安装
  5. 最长上升子序列O(nlogn)算法详解
  6. STM32学习笔记(一) 如何新建一个STM32工程模板
  7. goldengate 12c对oracle DB的改进
  8. [POJ 2923] Relocation (动态规划 状态压缩)
  9. 【BZOJ】【1050】【HAOI2006】旅行comf
  10. Java [leetcode 8] String to Integer (atoi)
  11. hashCode()和equals()的用法
  12. JavaScript高级程序设计38.pdf
  13. Linux中tar命令-C用法
  14. IController控制器的创建过程
  15. Alamofire4.0&#160;在 CocoaPods无法更新的问题
  16. mac下eclipse安装svn插件-subclipse
  17. Vim安装使用和配置
  18. Javaweb拦截器
  19. canvas绘图history妙用
  20. js中创建数组,并往数组里添加元素

热门文章

  1. Fiddler抓包过滤
  2. JavaScript_Array
  3. input框处理大全
  4. 详解 Discuz 的 PHP经典加密解密函数 authcode
  5. (四)PL/SQL运算符
  6. [Qt] 去掉QMessageBox标题栏上的图标
  7. CTR学习笔记&amp;代码实现4-深度ctr模型 NFM/AFM
  8. 小米Note 10 Lite海外发布 无缘中国市场
  9. P1466 集合 Subset Sums 搜索+递推+背包三种做法
  10. 第K短路+严格第K短路