但問題就出在 Willi 告訴 Maja,在哪裡可以與他會面,要知道,Willi 是一個懶惰的蜜蜂,而 Maja 是一個勤勞的蜜蜂,所以他們對於鬧區有不同的座標看待方式。


首先,我們要找出座標規則,如同下圖所示:

依照以上觀念寫成 C 語言程式碼如下:
#define SIZE 100000最後在主程式如此呼叫:
struct point
{
int x, y;
};
struct point p[SIZE + 1];
int index;
void create()
{
p[1].x = 0, p[1].y = 0;
index = 2;
int nowI = 0, nowJ = 0, count, num;
for (num = 1; index <= SIZE; num ++)
{
for (count = 0; count < num && index <= SIZE; count ++, index ++)
p[index].x = nowI, p[index].y = ++ nowJ;
for (count = 0; count < num - 1 && index <= SIZE; count ++, index ++)
p[index].x = -- nowI, p[index].y = ++ nowJ;
for (count = 0; count < num && index <= SIZE; count ++, index ++)
p[index].x = -- nowI, p[index].y = nowJ;
for (count = 0; count < num && index <= SIZE; count ++, index ++)
p[index].x = nowI, p[index].y = -- nowJ;
for (count = 0; count < num && index <= SIZE; count ++, index ++)
p[index].x = ++ nowI, p[index].y = -- nowJ;
for (count = 0; count < num && index <= SIZE; count ++, index ++)
p[index].x = ++ nowI, p[index].y = nowJ;
}
}
create();
int n;
while (scanf("%d", &n) == 1)
printf("%d %d\n", p[n].x, p[n].y);
By David.K
p10182題目連結
回ACM題庫目錄
回首頁
沒有留言:
張貼留言