当前位置:网站首页>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;
}
边栏推荐
- Calculate weight and comprehensive score by R entropy weight method
- 想问下大家伙,有无是从腾讯云MYSQL同步到其他地方的呀?腾讯云MySQL存到COS上的binlog
- Database learning - Database Security
- P1451 calculate the number of cells / 1329: [example 8.2] cells
- 做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
- Reasons and solutions for redis cache penetration and cache avalanche
- 市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
- 华为哈勃化身硬科技IPO收割机
- Common redis data types and application scenarios
- Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
猜你喜欢
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
I spring web upload
Creation and optimization of MySQL index
Bugku's eyes are not real
Object. defineProperty() - VS - new Proxy()
Bugku cyberpunk
1330:【例8.3】最少步数
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
Bugku telnet
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
随机推荐
Bugku easy_ nbt
Ctfshow web entry information collection
episodic和batch的定义
数学建模之层次分析法(含MATLAB代码)
Magic methods and usage in PHP (PHP interview theory questions)
华为哈勃化身硬科技IPO收割机
MySQL之CRUD
我这边同时采集多个oracle表,采集一会以后,会报oracle的oga内存超出,大家有没有遇到的?
I spring web upload
Ionic Cordova project modification plug-in
Calculate weight and comprehensive score by R entropy weight method
First PR notes
CODING DevSecOps 助力金融企业跑出数字加速度
Bugku alert
Common PHP interview questions (1) (written PHP interview questions)
Machine learning notes - gray wolf optimization
[JVM] operation instruction
The difference between SQL Server char nchar varchar and nvarchar
把 ”中台“ 的思想迁移到代码中去
mapper. Comments in XML files