2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】

最短路径计算技巧

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343

Problem L. Graph Theory Homework

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1536    Accepted Submission(s): 830


Problem Description
There is a complete graph containing  n vertices, the weight of the i-th vertex is wi.
The length of edge between vertex i and j (ij) is |wiwj|−−−−−−−√.
Calculate the length of the shortest path from 1 to n.
 

 

Input
The first line of the input contains an integer  T (1T10) denoting the number of test cases.
Each test case starts with an integer n (1n105) denoting the number of vertices in the graph.
The second line contains n integers, the i-th integer denotes wi (1wi105).
 

 

Output
For each test case, print an integer denoting the length of the shortest path from  1 to n.
 

 

Sample Input
1
3
1 3 5
 

 

Sample Output
2
 

 

Source
 

 

题意概括:

给出每个点的权值,点与点之间的距离等于 √| wi-wj |  ,求起点到终点的最短距离。

 

解题思路:

一道伪装成图论的水题。

最短距离就是两点距离,因为如果中间放入其他点来进行更新路径是不会获得更短的路径的。

因为 √a + √b  > √(a+b) ;

AC code:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<vector>
 6 #include<queue>
 7 #include<cmath>
 8 #include<set>
 9 #define INF 0x3f3f3f3f
10 #define LL long long
11 using namespace std;
12 int N;
13 
14 int myabs(int x)
15 {
16     if(x < 0) return -x;
17     return x;
18 }
19 
20 int main()
21 {
22     int w, st, ed;
23     int T_case;
24     scanf("%d", &T_case);
25     while(T_case--){
26         scanf("%d", &N);
27         for(int i = 1; i <= N; i++){
28             scanf("%d", &w);
29             if(i == 1) st = w;
30             if(i == N) ed = w;
31         }
32         int ans = sqrt(myabs(st-ed));
33         printf("%d\n", ans);
34     }
35     return 0;
36 }
View Code

 

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
请你针对这部分修改,为避免样式改变 把样式代码也修改:.csw-h5-contest-racesSlots { padding: 12px 24px 0; .csw-opensource-h5-learningHeader { height: 24px; width: 100%; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; .csw-opensource-h5-learningHeader-title { color: rgb(0, 0, 0); font-size: 18px; font-weight: 500; line-height: 20px; } .csw-opensource-h5-learningHeader-more { color: rgb(153, 153, 153); font-size: 12px; font-weight: 400; line-height: 16px; .csw-opensource-h5-learningHeader-moreText { padding-right: 4px; } } } .csw-h5-contest-racesSlots-content { position: relative; .adm-jumbo-tabs-header { border: 0; .adm-jumbo-tabs-tab-list { padding: 0; .adm-jumbo-tabs-tab-wrapper { flex: none; padding: 0; margin-right: 16px; .adm-jumbo-tabs-tab { font-weight: 500; color: rgb(102, 102, 102); padding: 0; } .adm-jumbo-tabs-tab-active { color: rgb(0, 65, 211); } } } } .adm-jumbo-tabs-content { padding: 16px 0 12px; } .csw-h5-contest-topSummitsCarousel { width: 100%; padding-bottom: 12px; .topSummitsList { display: flex !important; justify-content: space-between; .topSummitsItem { width: 48%; position: relative; img { width: 100%; aspect-ratio: 1.785; border-radius: 4px; } .mask { width: 100%; height: 100%; position: absolute; bottom: 0; border-radius: 4px; } .maskCourse { position: absolute; top: 6px; right: 6px; display: inline-block; height: 20px; text-align: center; line-height: 20px; padding: 2px 8px 2px 8px; border-radius: 53px; background: rgba(0, 65, 211, 0.7); color: rgb(255, 255, 255); font-size: 11px; font-weight: 400; line-height: 16px; } .topSummitsItemTitle { display: inline-block; margin-top: 8px; width: 100%; color: rgb(0, 0, 0); font-weight: 400; line-height: 24px; } .itemSubTitle { font-family: HarmonyHeiTi; color: #666666; font-size: 12px; font-weight: 400; line-height: 19px; } } } .slick-dots-bottom { bottom: 3px; z-index: 9; li { height: 2px !important; width: 6px !important; } button { width: 6px !important; background: #f2f2f2 !important; opacity: 1 !important; border-radius: 30px !important; height: 2px !important; } .slick-active { width: 12px !important; border-radius: 1px !important; button { background-color: rgb(0, 65, 211) !important; width: 12px !important; } } } } .csw-racesSlots-h5-more { color: rgb(153, 153, 153); font-size: 12px; font-weight: 400; line-height: 16px; position: absolute; right: 0; top: 17px; .anticon-right { margin-left: 3px; } } .moreDomCss { position: absolute; top: 4px; right: 0; color: rgb(153, 153, 153); font-size: 12px; font-weight: 400; line-height: 16px; .moreText { padding-right: 4px; } } } }
11-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值