当前位置:网站首页>D-snow halo solution
D-snow halo solution
2022-07-05 15:25:00 【wch(】
D- Snow halo problem solution
label : Analytic geometry
subject

Ideas
The topic is actually relatively simple , Using high school mathematics can do , Unfortunately, I didn't finish reading the title during the competition
But because of IQ offline just now wa It took several rounds to pass
The problem is the shortest distance from a point to a line segment , It needs to be discussed on a case by case basis
First, determine the triangle formed by line segments and points Whether there is obtuse angle on one side of the line segment , You can use vectors to judge .
If a line segment is an edge, there is no obtuse angle Obviously, the shortest distance is the distance between the point and the straight line ,
Available formulas
Calculation
If there is obtuse angle Then the shortest distance is the smaller one from the point to both ends of the line
In addition, pay attention not to use long long Otherwise, it will be out of range .
Code implementation
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
double ans = 999999999;
double x1, y1, x2, y2;
int n;
cin >> n;
cin >> x1 >> y1;
cin >> x2 >> y2;
x1 -= x2;
y1 -= y2;// Make Xiaoguo at the origin relative to Xiaohong running , Convenient formula calculation
while (n--) {
cin >> x2 >> y2;
x2 += x1;
y2 += y1;
double a, c, d1, d2;
d2 = sqrt(min(x1 * x1 + y1 * y1, x2 * x2 + y2 * y2));
if ((x1 * (x2 - x1) + y1 * (y2 - y1) >= 0)||(x2*(x1-x2)+y2*(y1-y2)>=0)) ans = min(ans, d2);
else {
if (x1 - x2 != 0) {
a = (y1 - y2) / (x1 - x2);
c = y1 - a * x1;// A straight line -ax+y-c=0;
d1 = abs(c) / sqrt(a * a + 1);
ans = min(ans, d1);
}
else ans = min(ans, abs(x1));
}
x1 = x2;
y1 = y2;
}
printf("%0.12lf", ans);
return 0;
}
边栏推荐
- Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
- Redis distributed lock principle and its implementation with PHP (1)
- How to paste the contents copied by the computer into mobaxterm? How to copy and paste
- Detailed explanation of QT creator breakpoint debugger
- GPS original coordinates to Baidu map coordinates (pure C code)
- Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
- "Sequelae" of the withdrawal of community group purchase from the city
- 爱可可AI前沿推介(7.5)
- 当代人的水焦虑:好水究竟在哪里?
- CODING DevSecOps 助力金融企业跑出数字加速度
猜你喜欢

12 MySQL interview questions that you must chew through to enter Alibaba

Thymeleaf uses background custom tool classes to process text

当代人的水焦虑:好水究竟在哪里?

Fr exercise topic - simple question

Creation and use of thymeleaf template

CODING DevSecOps 助力金融企业跑出数字加速度

JS knowledge points-01

Huiyuan, 30, is going to have a new owner

Machine learning notes - gray wolf optimization

Object. defineProperty() - VS - new Proxy()
随机推荐
Interpretation of Apache linkage parameters in computing middleware
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
Leetcode: Shortest Word Distance II
wxml2canvas
MySQL----函数
Creation and optimization of MySQL index
Redis' transaction mechanism
【jvm】运算指令
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Common MySQL interview questions
MySQL 巨坑:update 更新慎用影响行数做判断!!!
Common interview questions about swoole
Redis distributed lock principle and its implementation with PHP (2)
ionic cordova项目修改插件
Common redis data types and application scenarios
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
lvgl 显示图片示例
Mongdb learning notes
Select sort and bubble sort