find the most comfortable road

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5359    Accepted Submission(s): 2327

Problem Description
XX
星有许多城市,城市之间通过一种奇怪的高速公路SARS(Super Air Roam
Structure---超级空中漫游结构)进行交流,每条SARS都对行驶在上面的Flycar限制了固定的Speed,同时XX星人对
Flycar的“舒适度”有特殊要求,即乘坐过程中最高速度与最低速度的差越小乘坐越舒服
,(理解为SARS的限速要求,flycar必须瞬间提速/降速,痛苦呀 ),
但XX星人对时间却没那么多要求。要你找出一条城市间的最舒适的路径。(SARS是双向的)。
 
Input
输入包括多个测试实例,每个实例包括:
第一行有2个正整数n (1<n<=200)和m (m<=1000),表示有N个城市和M条SARS。
接下来的行是三个正整数StartCity,EndCity,speed,表示从表面上看StartCity到EndCity,限速为speedSARS。speed<=1000000
然后是一个正整数Q(Q<11),表示寻路的个数。
接下来Q行每行有2个正整数Start,End, 表示寻路的起终点。
 
Output
每个寻路要求打印一行,仅输出一个非负整数表示最佳路线的舒适度最高速与最低速的差。如果起点和终点不能到达,那么输出-1。
 
Sample Input
4 4
1 2 2
2 3 4
1 4 1
3 4 2
2
1 3
1 2
 
Sample Output
1
0
题解:错了好多次啊。。。
代码:
 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int INF=0x7f7f7f7f;
const int MAXN=;
const int MAXM=;
int pre[MAXN];
struct Node{
int u,v,d;
};
Node dt[MAXM];
int cmp(Node a,Node b){
return a.d<b.d;
}
int find(int x){
int r=x;
while(r!=pre[r])r=pre[r];
// pre[x]=r;
return r;
}
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=;i<m;i++){
scanf("%d%d%d",&dt[i].u,&dt[i].v,&dt[i].d);
}
sort(dt,dt+m,cmp);
int Q,s,e,f1,f2;
scanf("%d",&Q);
while(Q--){
int ans=INF;//这个竟然被我写到外边
scanf("%d%d",&s,&e);
for(int j=;j<m;j++){
for(int i=;i<=n;i++)pre[i]=i;
for(int i=j;i<m;i++){
int u=dt[i].u,v=dt[i].v,d=dt[i].d;
f1=find(u);f2=find(v);
if(f1!=f2)pre[f2]=f1;
if(find(s)==find(e)){
ans=min(ans,d-dt[j].d);
break;
}
}
}
if(ans==INF)puts("-1");
else printf("%d\n",ans);
}
}
return ;
}
 

find the most comfortable road(并差集,找差值最小的权值)的更多相关文章

  1. HDU 1598 find the most comfortable road(最小生成树之Kruskal)

    题目链接: 传送门 find the most comfortable road Time Limit: 1000MS     Memory Limit: 32768 K Description XX ...

  2. hdu 1598 find the most comfortable road(枚举+卡鲁斯卡尔最小生成树)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. HDU 1598 find the most comfortable road 并查集+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000 ...

  4. HDU 1598 find the most comfortable road (MST)

    find the most comfortable road Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  5. HDU-1598 find the most comfortable road

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. HDU 1589 Find The Most Comfortable Road 最小生成树+枚举

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  7. HDU1598 find the most comfortable road 【并查集】+【枚举】

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. find the most comfortable road(hdu1598)不错的并查集

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. hdu 1598 find the most comfortable road (并查集+枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000/ ...

随机推荐

  1. leetcode two sum python

    class Solution: # @param {integer[]} nums # @param {integer} target # @return {integer[]} def twoSum ...

  2. .Net跨平台中遇到的问题小结

    一:创建MVC网站,需要修改Views视图文件夹下的Web.config 二:需要添加web.config中的 <system.web> <compilation debug=&qu ...

  3. linux 定时执行任务

    测试可以了,做个笔记 系统是centos 6.3 1,直接命令 crontab -e 编辑文件,里面写时间和你想要执行的命令. 例子 */1 * * * * sh /home/guanliyang/t ...

  4. 灰度直方图及处理“cvQueryHistValue_1D”: 找不到标识符”的问题(上)

    // HIstogram.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "opencv2/opencv.hpp ...

  5. Windows Azure Camp---漫步云端,创意无限

    不再需要一系列繁杂的网银密码,一键搞定所有的支付:与朋友约会时通过实时分享地理位置迅速找到对方,这些都可以在WindowsAzure平台得以实现.在刚刚结束的2013年微软学生夏令营中,来自全国30所 ...

  6. S3C6410 GPIO操作接口

    在后面的驱动学习中,需要对GPIO进行一系列的操作,了解这些引脚操作有助于编码的效率. 一.配置GPIO S3C6410要使用其引脚时,需要对其进行配置,如配置为输入/输出/中断等功能,根据芯片手册来 ...

  7. 第七届河南省赛10403: D.山区修路(dp)

    10403: D.山区修路 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 69  Solved: 23 [Submit][Status][Web Bo ...

  8. Lua环境配置 windows + VS

    环境搭建: 首先从 http://www.lua.org/ftp/下载lua 源码, 我选择的是lua-5.1.5.tar.gz 我的开发环境是Win7+ VS2010 打开VS2010新建一个工程L ...

  9. HTML5地理定位,百度地图API,知识点熟悉

    推断浏览器的兼容问题: IE9+支持地理定位,FF Chrome新版支持地理定位  if (navigator.geolocation) {        alert('支持地理定位');   } e ...

  10. JavaFx初探

    由于项目的须要,实在是没有办法了,试了非常多种方案(RCP,SWT,Flex,Smartinvoke...),终于还是决定開始研究JavaFx...为了给用户更好地体验我们的"智能家居&qu ...