AcWing 1237. 螺旋折线
原题链接
中等
作者:
EXQS
,
2021-04-13 19:50:57
,
所有人可见
,
阅读 289
#include <iostream>
#include <cmath>
#include <algorithm>
typedef long long LL;
using namespace std;
int main() {
LL x, y, ans = 0, n = 0, d = 0;
cin >> x >> y;
if (y > 0 && abs(x) <= y) {
n = y;
d = y - x + 2 * y;
} else if (x > 0 && abs(y) <= x) {
n = x;
d = x + y;
} else if (y < 0 && y - 1 <= x && -y >= x) {
n = -y;
d = x + y;
} else if (x < 0 && -x >= y && y >= x + 1) {
n = -x - 1;
d = -(y - x - 1 + (-x) * 2 - 1);
}
cout << (2 + (2 * n - 1)) * 2 * n - d << endl;
return 0;
}