原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962

分析:最短路+二分。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#define ll long long
#define inf 1000000000
#define maxn 1005
using namespace std;
struct edge
{
int to,h,len;
edge(int x,int y,int z)
{
to=x;h=y;len=z;
}
};
vector<edge>e[maxn];
queue<int>q;
bool vis[maxn];
int d[maxn],n,m,s,t,H,maxh;
void spfa(const int s,int h)
{
while(!q.empty())q.pop();
for(int i=;i<=n;i++)
{
d[i]=inf;vis[i]=false;
}
d[s]=;vis[s]=true;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=;i<e[u].size();i++)
{
if(e[u][i].h>=h&&d[e[u][i].to]>d[u]+e[u][i].len)
{
d[e[u][i].to]=d[u]+e[u][i].len;
if(!vis[e[u][i].to])
{
vis[e[u][i].to]=true;
q.push(e[u][i].to);
}
}
}
vis[u]=false;
}
}
int main()
{
int cas=;
while(~scanf("%d%d",&n,&m))
{
if(n==&&m==)break;
for(int i=;i<maxn;i++)e[i].clear();
int u,v,h,l;
for(int i=;i<m;i++)
{
scanf("%d%d%d%d",&u,&v,&h,&l);
if(h==-)h=inf;
e[u].push_back(edge(v,h,l));
e[v].push_back(edge(u,h,l));
}
scanf("%d%d%d",&s,&t,&H);
int lef=,r=H,maxh=,ans=inf;
while(lef<=r)
{
int mid=(r+lef)>>;
if(mid<=)break;
spfa(s,mid);
if(d[t]!=inf)
{
lef=mid+;
maxh=mid;
ans=d[t];
}
else r=mid-;
}
if(cas>) puts("");
printf("Case %d:\n",cas++);
if(ans==inf||maxh<)cout<<"cannot reach destination\n";
else {
printf("maximum height = %d\n",maxh);
printf("length of shortest route = %d\n",ans);
}
}
return ;
}

HDU--2962的更多相关文章

  1. hdu 2962 Trucking (二分+最短路Spfa)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...

  2. Trucking(HDU 2962 最短路+二分搜索)

    Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 2962 Trucking

    题目大意:给定无向图,每一条路上都有限重,求能到达目的地的最大限重,同时算出其最短路. 题解:由于有限重,所以二分检索,将二分的值代入最短路中,不断保存和更新即可. #include <cstd ...

  4. hdu 2962 最短路+二分

    题意:最短路上有一条高度限制,给起点和最大高度,求满足高度最大情况下,最短路的距离 不明白为什么枚举所有高度就不对 #include<cstdio> #include<cstring ...

  5. hdu 2962 Trucking (最短路径)

    Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. HDU - 2962 Trucking SPFA+二分

    Trucking A certain local trucking company would like to transport some goods on a cargo truck from o ...

  7. UVALive 4223 / HDU 2962 spfa + 二分

    Trucking Problem Description A certain local trucking company would like to transport some goods on ...

  8. hdu 2962 题解

    题目 题意 给出一张图,每条道路有限高,给出车子的起点,终点,最高高度,问在保证高度尽可能高的情况下的最短路,如果不存在输出 $ cannot  reach  destination $ 跟前面 $ ...

  9. Day4 - I - Trucking HDU - 2962

    A certain local trucking company would like to transport some goods on a cargo truck from one place ...

  10. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

随机推荐

  1. 3.hive的thriftserver服务

    1.ThiftServer介绍 正常的hive仅允许使用HiveQL执行查询.更新等操作,并且该方式比较笨拙单一.幸好Hive提供了轻客户端的实现,通过HiveServer或者HiveServer2, ...

  2. JS中自定义事件的使用与触发

    1. 事件的创建 JS中,最简单的创建事件方法,是使用Event构造器: var myEvent = new Event('event_name'); 但是为了能够传递数据,就需要使用 CustomE ...

  3. 2017软工 — 每周PSP

    1. PSP表格 2. PSP饼图 3. 本周进度条 4. 累计折线图

  4. 测试bug

    模板在运行时出现了以下 1 个错误:---------------------------Controller.tt(-1,-1) : error : 获取 AppDomain 以便从主机运行转换时出 ...

  5. BETA阶段第一天

    1.提供当天站立式会议照片一张 2.每个人的工作 今天完成工作 林一心 服务器调试 张杭镖 数据库调整 赵意 前端设计 江鹭涛 前端设计 3.发布项目燃尽图 4.每日每人总结 林一心:服务器端的配置不 ...

  6. iOS- Autolayout自动布局

    1.前言 •在iOS程序中,大部分视图控制器都包含了大量的代码用于设置UI布局,设置控件的水平或垂直位置,以确保组件在不同版本的iOS中都能得到合理的布局 •甚至有些程序员希望在不同的设备使用相同的视 ...

  7. ngx_http_rewrite_module(重定向)

    1:指定rewrite规则 rewrite regex replacement [flag];   什么是rewrite规则:If the specified regular expression m ...

  8. MiniOS系统

    实验一  命令解释程序的编写 一.目的和要求 1. 实验目的 (1)掌握命令解释程序的原理: (2)*掌握简单的DOS调用方法: (3)掌握C语言编程初步. 2.实验要求 编写类似于DOS,UNIX的 ...

  9. C语言文法阅读与理解

    <翻译单元>--><外部声明>--><函数定义>|<申报> <函数定义>--><声明说明符>-->< ...

  10. 关于解决java读取excel文件遇空行抛空指针的问题 !

    关于解决java读取excel文件遇空行抛空指针的问题 ! package exceRead; import java.io.File; import java.io.FileInputStream; ...