当前位置:网站首页>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;
}
边栏推荐
- maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
- R 熵权法计算权重及综合得分
- 机器学习框架简述
- 想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
- Common MySQL interview questions
- [recruitment position] infrastructure software developer
- episodic和batch的定义
- The difference between abstract classes and interfaces in PHP (PHP interview theory question)
- Mongdb learning notes
- Coding devsecops helps financial enterprises run out of digital acceleration
猜你喜欢
随机推荐
episodic和batch的定义
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
Array sorting num ranking merge in ascending order
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
Bugku's steganography
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
Huawei Hubble incarnation hard technology IPO harvester
go学习 ------jwt的相关知识
I collect multiple Oracle tables at the same time. After collecting for a while, I will report that Oracle's OGA memory is exceeded. Have you encountered it?
百亿按摩仪蓝海,难出巨头
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
JS bright blind your eyes date selector
Redis distributed lock principle and its implementation with PHP (2)
Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
wxml2canvas
数学建模之层次分析法(含MATLAB代码)
1330: [example 8.3] minimum steps
[recruitment position] Software Engineer (full stack) - public safety direction
华为哈勃化身硬科技IPO收割机
JMeter performance test: serveragent resource monitoring








![[JVM] operation instruction](/img/f5/85580495474ef58eafbb421338e93f.png)