hdu1598 find the most comfortable road
2015-12-04 16:13
169 查看
find the most comfortable road
Problem Description
XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure—超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Flycar的“舒适度”有特殊要求,即乘坐过程中最高速度与最低速度的差越小乘坐越舒服 ,(理解为SARS的限速要求,flycar必须瞬间提速/降速,痛苦呀 ),
但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。
题解:
这道虽然表面上与最短路径有关 其实这道题是求最小速度差,我一开始还用floyd来做 还用了并查集 其实这道题就是 用一下贪心的思想,我们枚举最小的速度差,如果这个速度差能使首尾在同一联通分量,就输出Problem Description
XX星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam Structure—超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对 Flycar的“舒适度”有特殊要求,即乘坐过程中最高速度与最低速度的差越小乘坐越舒服 ,(理解为SARS的限速要求,flycar必须瞬间提速/降速,痛苦呀 ),
但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。
[code]#include<iostream> using namespace std; #include<cstdio> #include<cstring> #include<algorithm> const int inf=0x3f3f3f3f; int f[1001]; struct note { int st,ai,s; } p[1001]; int n,m; int start,aim,c; int cmp(note aa,note aaa) { return (aa.s<aaa.s); } int finds(int x) { if(x!=f[x]) f[x]=finds(f[x]); return f[x]; } void init() { for(int i=1; i<=n; i++) f[i]=i; } int main() { while(scanf("%d%d",&n,&m)!=-1) { for(int i=0; i<m; i++) { scanf("%d%d%d",&p[i].st,&p[i].ai,&p[i].s); } sort(p,p+m,cmp); scanf("%d",&c); while(c--) { scanf("%d%d",&start,&aim); int ans=inf; int j; for(int i=0; i<m; i++) { init(); for( j=i; j<m; j++) { int x=finds(p[j].st); int y=finds(p[j].ai); if(x!=y) f[x]=y; int tx=finds(start); int ty=finds(aim); if(tx==ty) { int mins=(p[j].s-p[i].s); ans=(ans>mins)?mins:ans; break; } } } printf("%d\n",(ans==inf)?(-1):ans); } } return 0; }
相关文章推荐
- 6S设备开关飞行模式私有API失效及解决办法
- 关于JAVA(TM) Platfrom SE binary内存过高的问题
- 记录一下ORACLE 10gR2的软件下载地址,备用。
- iOS开发-多线程-NSThread
- 屏幕录像专家V7.5(完美破解版,无水印)下载
- ERROR 1269 (HY000): Can't revoke all privileges for one or more of the requested users
- Android调用系统自带的文件管理器进行文件选择
- 8天学通MongoDB——第一天 基础入门
- 修改root密码时出现错误passwd: Authentication token
- ZigZag Conversion
- PHP基础--分支语句和array操作
- Unity Splash Image 与 Launch场景的背景图无缝衔接
- linux下编译gsoap+onvif
- (java)蓝桥杯入门训练
- MPI+WIN10并行试运行
- django通用视图
- 【转】ffmpeg参数中文详细解释
- AOP那点事儿:面向切面编程(1)
- DevExpress Gridview数据源更新几个简单操作
- ffmpeg tutorial3 杂音