【hdu1030】“坐标表示法”
2024-08-30 12:53:51
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 ;
}
最新文章
- css浮动与绝对定位小记
- 24SQL
- 六、GAIA
- ubuntu 12.04下zmap安装
- 最长上升子序列O(nlogn)算法详解
- STM32学习笔记(一) 如何新建一个STM32工程模板
- goldengate 12c对oracle DB的改进
- [POJ 2923] Relocation (动态规划 状态压缩)
- 【BZOJ】【1050】【HAOI2006】旅行comf
- Java [leetcode 8] String to Integer (atoi)
- hashCode()和equals()的用法
- JavaScript高级程序设计38.pdf
- Linux中tar命令-C用法
- IController控制器的创建过程
- Alamofire4.0&#160;在 CocoaPods无法更新的问题
- mac下eclipse安装svn插件-subclipse
- Vim安装使用和配置
- Javaweb拦截器
- canvas绘图history妙用
- js中创建数组,并往数组里添加元素