当前位置:网站首页>Helix distance of point
Helix distance of point
2022-06-24 23:26:00 【Stay--hungry】

Ideas :
For point A ( x , y ) A(x,y) A(x,y), First, determine which area the point belongs to

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 )

Looking for a regular , Find out B B B The distance to the origin ∣ B O ∣ |BO| ∣BO∣

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;
}
边栏推荐
- [JS] - [array application] - learning notes
- InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
- Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training
- Fibonacci
- websocket长链接压测
- Building Survey [2]
- Construction equipment [5]
- Selection (025) - what is the output of the following code?
- HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
- Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
猜你喜欢

What good smart home brands in China support homekit?

Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk

Laravel pagoda security configuration

22map introduction and API

Simpledateformat concrete classes for formatting and parsing dates

国内有哪些好的智能家居品牌支持homekit?

Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis

02_ Springboot starter case

Detailed explanation of online group chat and dating platform project (servlet implementation)
随机推荐
Use of laravel verifier
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
Basic data type
golang convert map to json string
R语言dplyr包select函数将dataframe数据中的指定数据列移动到dataframe数据列中的第一列(首列)
7-6 铺设油井管道
F29oc analysis
Laravel user authorization
RT-thread使用rt-kprintf
记录一下MySql update会锁定哪些范围的数据
Building Survey [2]
Écoutez le fichier markdown et mettez à jour Hot next. Page JS
Blogs personal blog project details (servlet implementation)
378. Knight placement
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after the
02_ Springboot starter case
Whereabouts computer desktop small arrow
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and performs Welch double sample t-test analysis and double inde
并发之共享模型管程
File contains vulnerability issues