当前位置:网站首页>Helix distance of point

Helix distance of point

2022-06-24 23:26:00 Stay--hungry

Original link

 Insert picture description here

Ideas :

  • For point A ( x , y ) A(x,y) A(x,y), First, determine which area the point belongs to
     Insert picture description here

  • Then find out where the point is “ ray ” The endpoint of B ( a , b ) B(a,b) B(a,b)( find Endpoint coordinates and ( x , y ) (x,y) (x,y) The relationship between
     Insert picture description here

  • Looking for a regular , Find out B B B The distance to the origin ∣ B O ∣ |BO| BO
     Insert picture description here

  • seek ∣ A O ∣ |AO| AO Turn into : ∣ A O ∣ = ∣ B O ∣ + ∣ A B ∣ |AO|=|BO|+|AB| AO=BO+AB

#include <iostream>
using namespace std;
typedef long long LL;

int main()
{
    
    int x, y;
    cin >> x >> y;

    int a, b; // Endpoint coordinates of rays 
    LL d; // The distance from the endpoint to the origin 

    if (-y <= x && x <= y)  //  On the top 
    {
    
        a = -y, b = y;
        d = (LL)2 * abs(a) * (2 * abs(a) - 1);
        cout << d + x - a;
    }
    else if (-x <= y && y <= x)  //  On the right 
    {
    
        a = x, b = x;
        d = (LL)2 * a * 2 * a;
        cout << d + b - y;
    }
    else if (y - 1 <= x && x <= -y)  //  Below 
    {
    
        a = -y, b = y;
        d = (LL)2 * abs(a) * (2 * abs(a) + 1);
        cout << d + a - x;
    }
    else  //  On the left 
    {
    
        a = x, b = x + 1;
        d = (LL)(2 * abs(a) - 1) * (2 * abs(a) - 1);
        cout << d + y - b;
    }

    return 0;
}
原网站

版权声明
本文为[Stay--hungry]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241751286755.html