当前位置:网站首页>【acwing】1125. 牛的旅行***(floyd)
【acwing】1125. 牛的旅行***(floyd)
2022-04-21 23:22:00 【percation】

1.floyd求出任意两点之间的最短距离
2.求maxd[i],表示和i联通的且距离i最远的点的距离
3.
情况1:所有maxd[i]的最大值
情况2:枚举在哪两个点之间连边。i,j,需要满足d[i,j] = INF.maxd[i] + dis[i,j] + maxd[j];
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair<double,double> pii;
const int N = 2e2 + 10;
const double INF = 1e20;
char g[N][N];
int n,m;
pii q[N];
double dis[N][N], maxd[N];
void floyd(){
//floyd求出任意两点之间的最短距离
for(int k = 0; k < n; k++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
}
double get_dist(pii a, pii b){
double dx = a.x - b.x;
double dy = a.y - b.y;
return sqrt(dx*dx + dy * dy);
}
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> q[i].x >> q[i].y;
}
for(int i = 0; i < n; i++){
cin >> g[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i != j){
if(g[i][j] == '1'){
//说明联通,求两个点的路径
dis[i][j] = get_dist(q[i],q[j]);
}
else
dis[i][j] = INF;
}
}
}
floyd();
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(dis[i][j] < INF){
//联通说明距离小于INF
maxd[i] = max(maxd[i],dis[i][j]);
}
}
}
double res1 = 0;
for(int i = 0; i < n; i++){
res1 = max(res1,maxd[i]);
}
double res2 = INF;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(dis[i][j] >= INF){
//不连通,加边
res2 = min(res2,get_dist(q[i],q[j]) + maxd[i] + maxd[j]);
}
}
}
printf("%.6lf\n",max(res1,res2));
return 0;
}
版权声明
本文为[percation]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45866781/article/details/124332072
边栏推荐
- Finally, someone made it clear that this is the global one-piece network technology with low delay
- (10) RTSP video stream pulled by QT engineering ffmpeg in Ruixin micro rk3568
- BUUCTF 刷题记录
- [ffmpeg] command line
- The pattern should be large and the vision should be broad, and the humanitarian spirit should be upheld [continuous updating, do not delete]
- Golang force buckle leetcode 2246 Longest path with different adjacent characters
- Ruffian Heng embedded: talk about the application and influence of system watchdog wdog1 in the startup of i.mxrt1xxx system
- [wrapper (1)]
- 【ACM】46. Full Permutation (1. Here, the previous elements need to be used for permutation, so StartIndex is not used (only for combination and division); 2. Pay attention to whether the elements in t
- VOS6.0安装及源码命令
猜你喜欢

GIC spec之ITS和LPI中断5

Sélection et évolution des microservices dans l'architecture native du cloud

(7) Ruixin micro rk3568 builderoot adds compiled scripts and binary program files

(三)瑞芯微rk3568 ssh 替换 dropbear

Teach you to easily solve CSRF Cross Site Request Forgery Attack

新独立版抖音口红机全修复版本附视频教程

叹为观止,4款惊喜满满的高质量软件,使用起来倍感舒适

Buuctf question brushing record

早晚安打卡签到v2.0.1 公众号模块

(七)瑞芯微rk3568 buildroot 添加编译好的脚本和二进制程序文件
随机推荐
golang力扣leetcode 380.O(1)时间插入、删除和获取随机元素
(七)瑞芯微rk3568 buildroot 添加编译好的脚本和二进制程序文件
[wrapper (1)]
8.4 control of wheel motion of mobile robot in rodf robot modeling
技术、产品、品牌都不是问题,对上汽奥迪而言,这2点或生死攸关
IJCAI2022录用结果出炉!接收率15%,你中了吗?
Custom login successfully processed
点滴浓缩洁净,洗衣液行业的破局之路
【H.264】简单编码器及SPS
自定义登录成功处理
Classified summary of series articles (second issue)
红星美凯龙阵痛:“挥刀“降杠杆、净利率腰斩
从零开始自制实现WebServer(十六)---- 学习新工具CMake自动编写MakeFile 分门别类整理源文件心情愉悦
Ros2 robot modeling URDF 8.2rviz2 visual mobile robot model
系列文章分类汇总(第二期)
A collection of large factories and face classics. Do you know these knowledge points
MySQL problem solving_ Multi table joint query_ Take out the average probability that the user will brush the question again after one day
【openh264】SPS的 timing_info_present_flag
VOS6. 0 installation and source code command
【转载】Postman-Omysql连接数据库