当前位置:网站首页>点的螺旋距离
点的螺旋距离
2022-06-24 19:43:00 【Stay--hungry】

思路:
对于点 A ( x , y ) A(x,y) A(x,y),首先判断出该点属于上下左右哪个区域

再求出该点所在“射线”的端点 B ( a , b ) B(a,b) B(a,b)(找出端点坐标与 ( x , y ) (x,y) (x,y)之间的关系)

找规律,求出 B B B到原点的距离 ∣ B O ∣ |BO| ∣BO∣

求 ∣ A O ∣ |AO| ∣AO∣转化为: ∣ 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; //射线的端点坐标
LL d; //端点到原点的距离
if (-y <= x && x <= y) // 在上方
{
a = -y, b = y;
d = (LL)2 * abs(a) * (2 * abs(a) - 1);
cout << d + x - a;
}
else if (-x <= y && y <= x) // 在右方
{
a = x, b = x;
d = (LL)2 * a * 2 * a;
cout << d + b - y;
}
else if (y - 1 <= x && x <= -y) // 在下方
{
a = -y, b = y;
d = (LL)2 * abs(a) * (2 * abs(a) + 1);
cout << d + a - x;
}
else // 在左方
{
a = x, b = x + 1;
d = (LL)(2 * abs(a) - 1) * (2 * abs(a) - 1);
cout << d + y - b;
}
return 0;
}
边栏推荐
- OpenSSL SSL_ read: Connection was reset, errno 10054
- JD 618 conference tablet ranking list announced that the new dark horse brand staff will compete for the top three, learning from Huawei, the leader of domestic products
- Financial management [2]
- Écoutez le fichier markdown et mettez à jour Hot next. Page JS
- RT thread uses RT kprintf
- golang convert map to json string
- Blogs personal blog test point (manual test)
- idea创建模块提示已存在
- 【js】-【字符串-应用】- 学习笔记
- Financial management [6]
猜你喜欢

Concurrent shared model management

【js】-【字符串-应用】- 学习笔记

Blogs personal blog project details (servlet implementation)

对抗训练理论分析:自适应步长快速对抗训练

Blogs personal blog test point (manual test)

Epics record reference 4 -- fields for all input records and fields for all output records

伪原创智能改写api百度-收录良好

Ganglia 的安装与部署

Pseudo original intelligent rewriting API Baidu - good collection

2022 safety officer-a certificate examination questions and answers
随机推荐
Construction equipment [6]
Some updates about a hand slider (6-18, JS reverse)
376. 机器任务
2022 safety officer-a certificate examination questions and answers
【js】-【字符串-应用】- 学习笔记
Selection (026) - what is the output of the following code?
Record the range of data that MySQL update will lock
慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
#22Map介绍与API
Laravel message queue
Concurrent shared model management
去处电脑桌面小箭头
花房集团二次IPO:成于花椒,困于花椒
[text data mining] Chinese named entity recognition: HMM model +bilstm_ CRF model (pytoch) [research and experimental analysis]
Blogs personal blog project details (servlet implementation)
laravel 添加helper文件
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
Mycms we media CMS V3.0, resource push optimization, new free template
docker-mysql8-主从
Ganglia 的安装与部署