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 ...
随机推荐
- 一学就会pip换镜像源
首先介绍一个国内好用的镜像站 阿里云 http://mirrors.aliyun.com/pypi/simple/ 豆瓣 http://pypi.douban.com/simple/ 清华大学 htt ...
- Mybatis-Plus的填坑之路 - Lynwood/wunian7yulian
目录 Mybatis-Plus 我来填坑~ 目录 一.简单介绍 官方说明 : 成绩: 最新版本: 开发层面MyBatis-Plus特色 Mybatis-Plus中的Plus 二.MP的特性 三.MP框 ...
- 第五章—if语句
5-1 条件测试 :编写一系列条件测试:将每个测试以及你对其结果的预测和实际结果都打印出来.你编写的代码应类似于下面这样: car = 'subaru' print("Is car == ' ...
- Kafka安装之二 在CentOS 7上安装Kafka
一.简介 Kafka是由Apache软件基金会开发的一个开源流处理平台,由Scala和Java编写.Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据. 这 ...
- 《C》数据类型
- jsp取不到值栈的值
是否页面用的重定向? <result name="addsuccess" type="redirect"> ? 去掉type="redi ...
- 中国剩余定理---FZU 1402 猪的安家
J - 猪的安家 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 5433 Xiao Ming climbing 动态规划
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...
- C语言自评
问卷调查:你对自己的未来有什么规划?做了哪些准备?答:做设计方面的工作:正在努力自学有关这方面的知识 你认为什么是学习?学习有什么用?现在学习动力如何?为什么?答:学习就是增长见识:学习的作用就是为了 ...
- Lucene 常用名词解析
索引的创建:IndexWriter: 用于创建索引Directory: 这个可以用来定义我们的索引是存放在内存中还是在硬盘上Analyzer: 分词器 有几种()这个地方需要好好解释下Document ...