当前位置:网站首页>点的螺旋距离
点的螺旋距离
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;
}
边栏推荐
- golang convert map to json string
- Listen to the markdown file and hot update next JS page
- Getting started with the go Cobra command line tool
- Installation and deployment of ganglia
- SimpleDateFormat 格式化和解析日期的具体类
- 07_SpingBoot 实现 RESTful 风格
- 伪原创智能改写api百度-收录良好
- Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
- Pousser l'information au format markdown vers le robot nail
- Online group chat and dating platform test point
猜你喜欢

Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!

Blogs personal blog project details (servlet implementation)

Laravel pagoda security configuration

Pousser l'information au format markdown vers le robot nail

SimpleDateFormat 格式化和解析日期的具体类
![[JS] - [array, Stack, queue, Link List basis] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, Stack, queue, Link List basis] - Notes

推送Markdown格式信息到釘釘機器人
![[JS] - [string - application] - learning notes](/img/dc/f35979b094f04c0ee13b3354c7741d.png)
[JS] - [string - application] - learning notes

Getting started with the go Cobra command line tool

Servlet
随机推荐
【js】-【链表-应用】-学习笔记
laravel 消息队列
伪原创智能改写api百度-收录良好
Laravel message queue
Financial management [4]
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
第六章 网络学习相关技巧5(超参数验证)
Pseudo original intelligent rewriting API Baidu - good collection
docker-mysql8-主从
Simulated 100 questions and online simulated examination of high voltage electrician examination in 2022
监听 Markdown 文件并热更新 Next.js 页面
01_SpingBoot 框架入门
laravel model 注意事项
laravel 宝塔安全配置
SimpleDateFormat 格式化和解析日期的具体类
Laravel user authorization
laravel用户授权
Building Survey [2]
vulnhub DC: 2
Construction equipment [4]