当前位置:网站首页>点的螺旋距离
点的螺旋距离
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;
}
边栏推荐
- Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
- [JS] - [linked list - application] - learning notes
- Learn about redlock
- laravel 验证器的使用
- Laravel creates a service layer
- Laravel study notes
- No main manifest attribute in jar
- Push markdown format information to the nailing robot
- 01_ Getting started with the spingboot framework
- 【js】-【数组应用】-学习笔记
猜你喜欢

【js】-【链表-应用】-学习笔记

Canvas to add watermark to pictures

EMI的主要原因-工模电流

02_SpingBoot 入门案例
![[JS] - [array, stack, queue, linked list basics] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, stack, queue, linked list basics] - Notes

Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧

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

Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

From client to server
随机推荐
Do you need to improve your code reading ability? It's a trick
Uip1.0 active sending problem understanding
斐波那契
常用正则表达式
Websocket learning
Tech talk activity review kubernetes skills of cloud native Devops
Gocolly manual
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
372. 棋盘覆盖
【js】-【數組、棧、隊列、鏈錶基礎】-筆記
Push markdown format information to the nailing robot
Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
golang convert json string to map
03_SpingBoot 核心配置文件
【js】-【链表-应用】-学习笔记
EMI的主要原因-工模电流
Laravel scheduled task
How to submit the shopee opening and settlement flow?
Online group chat and dating platform test point
慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿