当前位置:网站首页>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;
}
边栏推荐
- Huiyuan, 30, is going to have a new owner
- Brief introduction of machine learning framework
- Array sorting num ranking merge in ascending order
- Redis distributed lock principle and its implementation with PHP (2)
- 把 ”中台“ 的思想迁移到代码中去
- mapper. Comments in XML files
- 美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
- Reasons and solutions for redis cache penetration and cache avalanche
- I spring and autumn blasting-1
- Number protection AXB function! (essence)
猜你喜欢

亿咖通科技通过ISO27001与ISO21434安全管理体系认证

Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP

Ctfshow web entry explosion

超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜

No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle

社区团购撤城“后遗症”

Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology

B站做短视频,学抖音死,学YouTube生?

Reasons and solutions for redis cache penetration and cache avalanche

MySQL之CRUD
随机推荐
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
可转债打新在哪里操作开户是更安全可靠的呢
30岁汇源,要换新主人了
MySQL 巨坑:update 更新慎用影响行数做判断!!!
easyOCR 字符识别
Redis distributed lock principle and its implementation with PHP (1)
Talk about your understanding of microservices (PHP interview theory question)
MySQL之CRUD
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
Reconnaissance des caractères easycr
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
keep-alive
Leetcode: Shortest Word Distance II
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
JS knowledge points-01
ICML 2022 | 探索语言模型的最佳架构和训练方法
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
ICML 2022 | explore the best architecture and training method of language model
Anaconda uses China University of science and technology source