博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu-1598 find the most comfortable road---kruskal+枚举下界
阅读量:7090 次
发布时间:2019-06-28

本文共 1626 字,大约阅读时间需要 5 分钟。

题目链接:

题目大意:

XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Flycar的“舒适度”有特殊要求,即乘坐过程中最高速度与最低速度的差越小乘坐越舒服 ,(理解为SARS的限速要求,flycar必须瞬间提速/降速,痛苦呀 ),

但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。

解题思路:

对边进行排序,从小到大枚举下界,依次加入每条边,知道恰好目标点连通,那么正好是最大值-最小值。答案取最小值

1 #include
2 using namespace std; 3 const int maxn = 1000 + 10; 4 const int INF = 0x3f3f3f3f; 5 struct node 6 { 7 int u, v, w; 8 bool operator <(const node & a)const 9 {10 return w < a.w;11 }12 }a[maxn];13 int p[maxn];14 void init()15 {16 for(int i = 0; i < maxn; i++)p[i] = i;17 }18 int Find(int x)19 {20 return x == p[x] ? x : p[x] = Find(p[x]);21 }22 void Union(int x, int y)23 {24 p[Find(x)] = Find(y);25 }26 int main()27 {28 int n, m;29 while(cin >> n >> m)30 {31 for(int i = 0; i < m; i++)32 {33 cin >> a[i].u >> a[i].v >> a[i].w;34 }35 sort(a, a + m);36 int t, u, v;37 cin >> t;38 while(t--)39 {40 cin >> u >> v;41 int ans = INF;42 for(int start = 0; start < m; start++)43 {44 init();45 for(int end = start; end < m; end++)46 {47 Union(a[end].u, a[end].v);48 if(Find(u) == Find(v))49 {50 ans = min(ans, a[end].w - a[start].w);51 }52 }53 }54 if(ans < INF)cout<
<

 

转载于:https://www.cnblogs.com/fzl194/p/8904011.html

你可能感兴趣的文章
python 获取VM物理机信息
查看>>
npm使用指南
查看>>
WPF文字描边的解决方法(二)——支持文字竖排和字符间距调整
查看>>
Android项目实战(四十五):Usb转串口通讯(CH34xUARTDriver)
查看>>
终于弄明白了Eclipse中Maven和SVN,真不容易!
查看>>
千鸟互联完成数千万元A+轮融资,从废纸回收切入打造工业纸产业闭环
查看>>
EDAS staragent 排查
查看>>
rocketMq-consumer介绍
查看>>
MySQL必须调整的10项配置优化
查看>>
【译】编写更好的CSS必备的40个工具
查看>>
Retrofit--合理封装回调能让你的项目高逼格
查看>>
Visual D 0.49.0 发布,支持 Visual Studio 2019
查看>>
[原创]同一个Tomcat,配置多个context、多个Host
查看>>
OSDI '18重磅解密:蚂蚁金服实时金融级分布式图数据库GeaBase
查看>>
Spring(十四)之编程性事务(续)
查看>>
读《股票大作手操盘术》— 利弗莫尔操作法则
查看>>
基于Opencv&Tensorflow实现实时查找停车位置
查看>>
Red Hat Enterprise Linux(RHEL)中yum的repo文件详解
查看>>
CSS3 是最新的 CSS 标准
查看>>
通过git工具提交文件到GitHub
查看>>