当前位置:网站首页>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;
}
边栏推荐
- Aike AI frontier promotion (7.5)
- lv_font_conv离线转换
- Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
- Ctfshow web entry explosion
- 可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
- sql server char nchar varchar和nvarchar的区别
- CODING DevSecOps 助力金融企业跑出数字加速度
- B站做短视频,学抖音死,学YouTube生?
- P1451 calculate the number of cells / 1329: [example 8.2] cells
- CODING DevSecOps 助力金融企业跑出数字加速度
猜你喜欢

爱可可AI前沿推介(7.5)

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

MySQL 巨坑:update 更新慎用影响行数做判断!!!

Redis' transaction mechanism

Transfer the idea of "Zhongtai" to the code

Detailed explanation of QT creator breakpoint debugger

30岁汇源,要换新主人了

Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking

Bugku's Eval

No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
随机推荐
Bubble sort, insert sort
你童年的快乐,都是被它承包了
Jmeter性能测试:ServerAgent资源监控
Fr exercise topic - simple question
P1451 求细胞数量/1329:【例8.2】细胞
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
30岁汇源,要换新主人了
Bugku easy_ nbt
Ionic Cordova project modification plug-in
如何将 DevSecOps 引入企业?
CSRF, XSS science popularization and defense
复现Thinkphp 2.x 任意代码执行漏洞
Bugku's Ping
Appium自动化测试基础 — APPium基础操作API(二)
Your childhood happiness was contracted by it
qt creater断点调试程序详解
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Bugku telnet
当代人的水焦虑:好水究竟在哪里?
MySQL----函数