解题思路:分成四个象限,单独计算即可
注意事项:记着开long long
参考代码:
#include <stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
long long x,y,t,dis;
scanf("%lld %lld",&x,&y);
if(x>=0&&y>=0){//第一象限
t=max(x,y);
dis = 4*t*t+x-y;
}
else if(x>0&&y<0){//第四象限
t=max(abs(x),abs(y));
dis = 2*t*(2*t+1)+abs(y)-abs(x);
}
else if(x<=0&&y<=0){//第三象限
x = abs(x);
y= abs(y)+1;
t=max(abs(x),(y));
dis = (t+t-1)*(t+t-1)+x-y;
}
else{//第二象限
t=max(abs(x),(y));
dis = 2*t*(2*t-1)+abs(y)-abs(x);
}
cout<<dis<<endl;
return 0;
}
0.0分
4 人评分