-7

I want to find if a point (x,y)where x,y integers satisfy the spiral square. (0,0) (0,1) (1,1) (1,2) (0,2) (-1,2) (-2,2) (-2,1) (-2,0) ans so on.....

enter image description here

How do I do it? I want the logic for a java or c++ function.

4

3 に答える 3

0

以下は、いくつかの疑似コード ロジックです。

Start with x=0, y=0, dist=0, direction=1
Loop
  x += (++dist * direction)
  WritePoint(x,y)
  y += (++dist * direction)
  WritePoint(x,y)
  direction *= -1
LoopEnd

そこから取ってください。

于 2014-08-10T13:39:10.470 に答える
0

次の操作を行います。

(operator)(operation)(amount)

ここで、演算子は x,y,x,y,... (そのためには % 演算子を使用) のように変わり、操作は +,+,-,-,+,+,-,-,+,+...(再びそのためには % 演算子を使用します)、量は 1,2,3,... のように変化します

于 2014-10-15T05:36:09.330 に答える