一、题目链接
二、题目分析
(一)算法标签
数学 找规律
(二)解题思路
左上角为:
(
2
n
−
1
)
(
2
n
)
(2n-1)(2n)
(2n−1)(2n)
右上角为:
(
2
n
)
2
(2n)^2
(2n)2
右上角为:
(
2
n
−
1
)
(
2
n
)
(2n-1)(2n)
(2n−1)(2n)
左下角为:
(
2
n
−
1
)
2
(2n-1)^2
(2n−1)2
三、AC代码
解法一:
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
int x, y;
cin >> x >> y;
int n = max(abs(x), abs(y));
LL res;
if (x == -n)
{
res = (LL)(2 * n - 1) * 2 * n - (n - y);
}
else if (x == n)
{
res = (LL)4 * n * n + (n - y);
}
else if (y == n)
{
res = (LL)(2 * n - 1) * 2 * n + (x + n);
}
else
{
res = (LL)(2 * n + 1) * (2 * n + 1) - (x + n) - 1;
}
cout << res;
return 0;
}