HDU--2962
原题链接: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的更多相关文章
- hdu 2962 Trucking (二分+最短路Spfa)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...
- Trucking(HDU 2962 最短路+二分搜索)
Trucking Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2962 Trucking
题目大意:给定无向图,每一条路上都有限重,求能到达目的地的最大限重,同时算出其最短路. 题解:由于有限重,所以二分检索,将二分的值代入最短路中,不断保存和更新即可. #include <cstd ...
- hdu 2962 最短路+二分
题意:最短路上有一条高度限制,给起点和最大高度,求满足高度最大情况下,最短路的距离 不明白为什么枚举所有高度就不对 #include<cstdio> #include<cstring ...
- hdu 2962 Trucking (最短路径)
Trucking Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU - 2962 Trucking SPFA+二分
Trucking A certain local trucking company would like to transport some goods on a cargo truck from o ...
- UVALive 4223 / HDU 2962 spfa + 二分
Trucking Problem Description A certain local trucking company would like to transport some goods on ...
- hdu 2962 题解
题目 题意 给出一张图,每条道路有限高,给出车子的起点,终点,最高高度,问在保证高度尽可能高的情况下的最短路,如果不存在输出 $ cannot reach destination $ 跟前面 $ ...
- Day4 - I - Trucking HDU - 2962
A certain local trucking company would like to transport some goods on a cargo truck from one place ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
随机推荐
- oracle数据库之组函数
组函数也叫聚合函数,用来对一组值进行运算,并且可以返回单个值 常见的组函数: (1)count(*),count(列名) 统计行数:找到所有不为 null 的数据来统计行数 (2)avg(列名) ...
- web _service 接口
1.WebService 就是 http请求 post接口 2.需要加 请求头信息 Content-Type: text/xml; 3.需要把占位符换成需要的字符串 webservice接口可以 ...
- #Ubuntu 18.04 安装tensorflow-gpu 1.9
参考 https://tensorflow.google.cn/install/install_linux http://nvidia.com/cuda http://developer.nvidia ...
- [T-ARA][Falling U]
歌词来源:http://music.163.com/#/song?id=27506041 作词:韩尚元 [作词:韩尚元] 作曲:韩尚元 [作曲:韩尚元] Love is pain Love is pa ...
- python实现中文验证码识别方法(亲测通过)
验证码截图如下: # coding:utf-8from PIL import Image,ImageEnhanceimport pytesseract#上面都是导包,只需要下面这一行就能实现图片文字识 ...
- python mongodb操作大全
数据库 增 use db1 #有则切换,无则新增 查 show dbs #查看所有 db #当前 删 db.dropDatabase() 集合: 增: db.user db.user.info db. ...
- centos上搭建git服务--4
Git是目前世界上最先进的分布式版本控制系统(没有之一).使用Svn的请参考<版本控制-svn服务器搭建和常用命令(centos 6.3)>,下面介绍Git的常用命令 常用命令 简单版 升 ...
- gulp配置文件(gulpfile.js)
需要安装的插件 "gulp": "^3.9.1","gulp-clean": "^0.3.2","gulp-c ...
- Alpha发布——美工+文案
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2283 一.功能介绍 本团队(可以低头,但没必要)开发的是一款基于腾讯微信 ...
- centos7环境下mysql安装
1.去官网下载合适的yum源安装包 https://dev.mysql.com/downloads/repo/yum/ 2.yum 本地安装 命令:yum localinstall mysql57-c ...