AcWing 1237. 螺旋折线
原题链接
中等
作者:
wjie
,
2020-07-01 17:19:39
,
所有人可见
,
阅读 739
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int x, y;
scanf("%d %d", &x, &y);
long long position = max(abs(x), abs(y));
long long res = 0;
if (y == -position)
res -= x + position;
else if (x == position)
res -= y + position + 2 * position;
else if (y == position)
res -= position - x + 4 * position;
else
res -= position - y + 6 * position;
// cout << res << endl;
long long jump = (2 + 2 * position) * position / 2 * 4;
res += jump;
printf("%lld", res);
return 0;
}