(defun calc-coor (sec)
"計算座標函式"
(if (equal sec 0)
(return-from calc-coor))
(let* (( sec (- sec 1))
(layer (+ (floor (sqrt sec)) 1))
(base (* layer (- layer 1)))
(displace (- sec base))
(coor (list layer layer)))
(if (equal (rem layer 2) 1)
(if (> displace 0)
(decf (first coor) displace)
(incf (second coor) displace))
(if (> displace 0)
(decf (second coor) displace)
(incf (first coor) displace)))
coor
))
(defun chess-board ()
(do ((sec (read) (read)))
((<= sec 0) )
(format t "~A~%" (calc-coor sec))))
(chess-board)
#include <stdio.h>
#include <math.h>
int main(int argc, char *argv[])
{
int N ;
int layer ;
int base ;
int displace ;
int coor[2] ;
while(scanf("%d",&N) && N){
N-- ;
layer = floor(sqrt(N))+1;
base = layer*(layer-1) ;
displace = N-base ;
coor[0] = coor[1] = layer ;
if(layer%2 == 1)
if(displace > 0)
coor[0] -= displace ;
else
coor[1] += displace ;
else
if(displace > 0)
coor[1] -= displace ;
else
coor[0] += displace ;
printf("%d %d\n", coor[0], coor[1]) ;
}
return 0;
}
題目連結:http://zerojudge.tw/ShowProblem?problemid=c048
沒有留言:
張貼留言