选择模板 |
最新日志 |
热门文章 |
- [536447]发布开心网外挂 之 争车位 Parker V1.0c
- [141843]关于3000本TXT电子书下载的事情(最新更新到1万5000本)
- [111173]发布开心网外挂 之 咬人助手 Biter V0.6f
- [87147]发布开心网外挂 之 争车位排行榜 Rank V1.1a
- [83935]发布开心网外挂 之 朋友买卖 Slave V0.6a
- [80948]开心网外挂开发手记
- [79045]开心网外挂 之 买房子 V0.2b
- [62226]打算公开给开心网写的所有外挂程序源代码
- [60920]I'm back!
- [54517]发布校内开心网Kaixin.com外挂 V0.3
- [52735]发布开心网外挂 之 马甲助手 AddFriends V1.1
- [50887]推荐一个免费的HTTP抓包分析工具 Fiddler Web Debugger
- [46845]关于开心网修复邻居车位BUG的处理办法
- [41566]发布开心网外挂 之 开心餐厅 Restaurant V0.1a
- [34944]2012.09.05.圣地亚哥野生动物园
最新评论 |
链接 |
- 默认链接组
- 回忆
- (前)自由天地
- 高中同学
- 心痣
- 永远的七班
- Adam429 Blog
- 沉檀清宵
- Seth Yang
- 有家客栈
- 重庆妹jingle
- 大学同学
- 笑对最好
- Rico.Wang's Blog
- 而立始旅
- 溯源
- Tech makes you smart
- Tower of Babylon
- 尹祥龙 - yxl
- 枫之魅
- 小翚
- SK log
- Moon River
- Jarod BLOG
- 丫丫
- Bur
- Yamir
- 地平线
- Skywind Inside
- 咔咔的棉花糖
- 硅基帝国(WangQ)
- 青蛙乱塘
- MrGump's BLOG
- Resurgence
- Justin's Blog
- Yu Zhang's Album
- 为了理想去追
- 牛魔王|长发|PeterPan
- xiaoningyb
- 流水人家
- YQ's BLOG
- 三宿桑下
- 五楼的阳光
- Sweet Coffee^-^
- Jemini's Space
- Ven's Memories
- Binny's Blog
- 朋友
- 飞鸟留痕
- On the way
- Ken Zheng's BLOG
- 12345
- I have no mouth, and I must scream
- 索索
- 偶爱偶家
- 非鱼知鱼乐
- Engineering Excellence
- 好站
- Slashdot
- PDAFans
- Mobile01
- DoNews.COM
- SouthPark Stuff
- 网不易
- Solidot
- 张馨予的BLOG
- Java Tips
- 机票查询--ET380.Com
- 當先生的實驗室
玮哥牛鼻阿
[font=\"courier new\"]
#include <stdio.h>
#include <assert.h>
#include <math.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : -(a))
int getRadius(int number)
&leftsign;
// (-b +/- sqrt(b^2 - 4ac)) / 2a
return (int)ceil((-1 + sqrt(1 + 4 * 2 * ((number + 5) / 6))) / 2);
&rightsign;
void getPos(int number, int *dx, int *dy, int *dz)
&leftsign;
assert (number >= 0);
int radius = getRadius(number);
if (radius == 0) &leftsign;
*dx = *dy = *dz = 0;
return;
&rightsign;
int x, y, z;
/* biggest number of inner circle */
int base = radius * (radius - 1) / 2 * 6;
/* the value of radius is also the length of one edge */
number -= base;
int edge = (number - 1) / radius;
switch (edge % 3) &leftsign;
case 0:
x = radius * (edge + 1) - number;
y = radius;
z = radius * edge - number;
break;
case 1:
x = radius * edge - number;
y = radius * (edge + 1) - number;
z = -radius;
break;
case 2:
x = -radius;
y = radius * edge - number;
z = number - radius * (edge + 1);
break;
default:
assert(0);
break;
&rightsign;
if (edge >= 3) &leftsign;
x = -x;
y = -y;
z = -z;
&rightsign;
*dx = x;
*dy = y;
*dz = z;
&rightsign;
int distance(int a, int b)
&leftsign;
int x1, y1, z1;
int x2, y2, z2;
getPos(a, &x1, &y1, &z1);
getPos(b, &x2, &y2, &z2);
return max(max(abs(x2 - x1), abs(y2 - y1)), abs(z2 - z1));
&rightsign;
int main()
&leftsign;
/* 测试案例略... */
return 0;
&rightsign;
[/font]