给你一个数,问你在如下的曲线递增的连续矩阵的坐标。
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;
}