1237. 螺旋折线


写吐了。。。

#include<iostream>
using namespace std;

#define LL long long

LL S(LL n){
    return  (4 * n + 1) * (n + 1);
}

int main(){
    LL x, y, res = 0;
    cin >> x >> y;
    
    LL maxv = max(abs(x), abs(y));
    
    if(y >= 0 && x <= 0) res += y + maxv + x; // 这里可以看出(x < 0, y = 0)是被算在更高一阶的,只不过res为0
    if(y > 0 && x > 0) res += maxv - y + x + maxv * 2;
    if(y <= 0 && x >= 0) res += maxv - x - y + maxv * 4;
    if(y < 0 && x < 0) res = - (++ maxv + x - y);
    
    res += S(maxv - 1);
    
    cout << res;
    
    return 0;
}
原文地址:https://www.cnblogs.com/tomori/p/13827550.html