当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity

华为机器学习服务语音识别功能,让应用绘“声”绘色

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan

Main cause of EMI - mold current

第六章 网络学习相关技巧5(超参数验证)

Record the range of data that MySQL update will lock

Simpledateformat concrete classes for formatting and parsing dates

并发之共享模型管程

idea创建模块提示已存在

【js】-【数组应用】-学习笔记
随机推荐
选择类排序法
[JS] - [tree] - learning notes
Force deduction solution summary 515- find the maximum value in each tree row
Building Survey [2]
Common regular expressions
国内有哪些好的智能家居品牌支持homekit?
378. Knight placement
Selection (027) - what is the output of the following code?
企业数据防泄露解决方案分享
Laravel message queue
Record the range of data that MySQL update will lock
Pseudo original intelligent rewriting API Baidu - good collection
No main manifest attribute in jar
7-2 后序+中序序列构造二叉树
常用正则表达式
golang convert map to json string
Still using simpledateformat for time formatting? Be careful of project collapse
Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk
22map introduction and API
文件包含漏洞问题