当前位置:网站首页>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;
}
边栏推荐
- Bugku cyberpunk
- Brief introduction of machine learning framework
- Fr exercise topic - simple question
- Talking about how dataset and dataloader call when loading data__ getitem__ () function
- Interpretation of Apache linkage parameters in computing middleware
- The elimination strategy of redis
- Misc Basic test method and knowledge points of CTF
- MySQL5.7的JSON基本操作
- ionic cordova项目修改插件
- Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
猜你喜欢
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
wxml2canvas
MySQL之CRUD
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
Coding devsecops helps financial enterprises run out of digital acceleration
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
1330:【例8.3】最少步数
你童年的快乐,都是被它承包了
华为哈勃化身硬科技IPO收割机
30岁汇源,要换新主人了
随机推荐
Hongmeng system -- Analysis from the perspective of business
GPS原始坐标转百度地图坐标(纯C代码)
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
Talk about your understanding of microservices (PHP interview theory question)
Coding devsecops helps financial enterprises run out of digital acceleration
Stm32+bh1750 photosensitive sensor obtains light intensity
wxml2canvas
Cartoon: what are the attributes of a good programmer?
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
Bugku's steganography
mapper.xml文件中的注释
Fr exercise topic - simple question
Reconnaissance des caractères easycr
你童年的快乐,都是被它承包了
MySQL5.7的JSON基本操作
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
1330:【例8.3】最少步数
JS bright blind your eyes date selector
12 MySQL interview questions that you must chew through to enter Alibaba
lv_font_conv离线转换