当前位置:网站首页>点的螺旋距离
点的螺旋距离
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;
}
边栏推荐
- Financial management [2]
- Dynamic menu, auto align
- File contains vulnerability issues
- laravel 创建 service层
- sql -CONVERT函数
- Detailed explanation of online group chat and dating platform project (servlet implementation)
- jar中没有主清单属性
- 监听 Markdown 文件并热更新 Next.js 页面
- 2022 safety officer-b certificate examination question bank and answers
- Selection (025) - what is the output of the following code?
猜你喜欢

Tech Talk 活动回顾|云原生 DevOps 的 Kubernetes 技巧
Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!

idea创建模块提示已存在
![[JS] - [tree] - learning notes](/img/62/de4fa2a7c5e52c461b8be4a884a395.png)
[JS] - [tree] - learning notes

RT-thread使用rt-kprintf
How should we measure agile R & D projects?

From client to server

InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog

记录一下MySql update会锁定哪些范围的数据

【js】-【数组、栈、队列、链表基础】-笔记
随机推荐
[JS] - [string - application] - learning notes
EMI的主要原因-工模电流
01_ Getting started with the spingboot framework
372. 棋盘覆盖
gocolly-手册
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
laravel 宝塔安全配置
Tech talk activity review kubernetes skills of cloud native Devops
Building Survey [3]
慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
Record the range of data that MySQL update will lock
【基础知识】~ 半加器 & 全加器
. Net 7 Preview 1 has been officially released
Whereabouts computer desktop small arrow
2022 safety officer-a certificate examination questions and answers
[JS] - [array application] - learning notes
websocket学习
Second IPO of Huafang group: grown up in Zanthoxylum bungeanum, trapped in Zanthoxylum bungeanum
Laravel add helper file
基本数据类型