UVA 10161-Ant on a Chessboard 简单模拟

来源:互联网 发布:sql创建存储过程 查询 编辑:程序博客网 时间:2024/05/18 02:11

给你一个数,问你在如下的曲线递增的连续矩阵的坐标。

25

24

23

22

21

10

11

12

13

20

9

8

7

14

19

2

3

6

15

18

1

4

5

16

17


直接模拟就好





#include<cstdio>#include<cstring>#include<cmath>using namespace std;int N;int resx, resy;int main(){    while (1)    {        scanf ("%d", &N);        if (N == 0) break;        int e = (int) sqrt (N);        int t = N - e * e;        if (t == 0)        {            if (e & 1)            {                resx = 1;                resy = e;            }            else            {                resx = e;                resy = 1;            }        }        else        {            if (e & 1)            {                if (t <= e + 1)                {                    resx = t;                    resy = e + 1;                }                else                {                    resx = e + 1;                    resy = e + 1 - (t - e - 1);                }            }            else            {                if (t <= e + 1)                {                    resx = e + 1;                    resy = t;                }                else                {                    resx = e + 1 - (t - e - 1);                    resy = e + 1;                }            }        }        printf ("%d %d\n", resx, resy);    }    return 0;}



0 0
原创粉丝点击