#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int x_1,y_1;cin>>x_1>>y_1;
if(x_1+y_1==0)
{
if(x_1>0) cout<<(2*x_1+1)*2*x_1<<endl;
if(x_1<0) cout<<(2*abs(x_1)-1)*2*abs(x_1)<<endl;
}
if(x_1==y_1) cout<<pow(2*x_1,2)<<endl;
if(x_1==y_1-1) cout<<pow(abs(x_1)+abs(y_1),2)<<endl;
//通过这四个角找四个边,利用线性规划
if(y_1>x_1&&y_1>-x_1)//在上方
{
ll step=x_1+y_1;
ll distance_0=(ll)(2*abs(y_1)-1)*2*abs(y_1);
ll distance=(ll)distance_0+step;
//cout<<distance_0<<endl;
cout<<distance<<endl;
}
else if(y_1<x_1&&y_1>-x_1)//在右方
{
ll step=x_1-y_1;
ll distance_0=(ll)2*x_1*2*x_1;
ll distance=(ll)distance_0+step;
//cout<<distance_0<<endl;
//cout<<step<<endl;
cout<<distance<<endl;
}
else if(y_1<x_1+1&&y_1<-x_1)//在下方
{
ll step=-x_1-y_1;
ll distance_0=(ll)(2*abs(y_1)+1)*2*abs(y_1);
ll distance=distance_0+step;
cout<<distance<<endl;
}
else if(y_1>x_1+1&&y_1<-x_1)//在左方
{
ll step=-x_1-y_1;
ll distance_0=(ll)(2*abs(x_1)-1)*2*abs(x_1);//往后数
ll distance=distance_0-step;
cout<<distance<<endl;
}
return 0;
}
先给大家看一下代码,然后这是图解,我一开始本来想推出数学规律,后来发现我只能推出角来,然后根据这四个角,三个线进行线性规划!