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

分析:最短路+二分。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#define ll long long
#define maxn 105
#define inf 0x7fffffff
using namespace std;
int T,n,m,low,up;
int h[maxn],map[maxn][maxn],h1[maxn];
int d[maxn];
bool vis[maxn];
struct edge
{
int to,len;
edge(int x,int y)
{
to=x;len=y;
}
};
vector<edge>e[maxn];
queue<int>q;
void spfa(const int s)
{
while(!q.empty())q.pop();
for(int i=;i<=n;i++)
{
d[i]=inf;vis[i]=false;
}
d[s]=;vis[s]=true;
if(h[s]<low||h[s]>up)return;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=;i<e[u].size();i++)
{
if(h[e[u][i].to]>=low&&h[e[u][i].to]<=up)
{
int tmp=d[u]+e[u][i].len;
if(d[e[u][i].to]>tmp)
{
d[e[u][i].to]=tmp;
if(!vis[e[u][i].to])
{
vis[e[u][i].to]=true;
q.push(e[u][i].to);
}
}
}
}
vis[u]=false;
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
for(int i=;i<maxn;i++)e[i].clear();
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&h[i]);
h1[i]=h[i];
}
sort(h1+,h1+n+);
int u,v,len;
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&len);
e[u].push_back(edge(v,len));
e[v].push_back(edge(u,len));
}
int dif=inf,ans,minlen=inf;
int l=,r=h1[n]-h1[];
while(l<=r)
{
int mid=(l+r)>>;
bool flag=false;
for(int i=;i<=n;i++)
{
low=h1[i];
up=low+mid;
spfa();
if(d[n]!=inf)
{
flag=true;
ans=d[n];
break;
}
}
if(flag)
{
r=mid-;
if(dif>mid)
{
dif=mid;
minlen=ans;
}
else if(dif==mid&&ans<minlen)
minlen=ans;
}
else l=mid+;
}
printf("%d %d\n",dif,minlen);
}
return ;
}

HDU--2363的更多相关文章

  1. hdu 2363(枚举+最短路好题)

    Cycling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  2. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  3. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  4. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  5. hdu 3191 How Many Paths Are There (次短路径数)

    How Many Paths Are There Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  6. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  7. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  10. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Spring学习(3):Spring架构(转载)

    1. Spring架构图 核心容器:包括Core.Beans.Context.EL模块. ●Core模块:封装了框架依赖的最底层部分,包括资源访问.类型转换及一些常用工具类. ●Beans模块:提供了 ...

  2. mysql 5.5 zip配置安装

    1.解压2.创建option文件 --defaults-file=../my.ini [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mys ...

  3. Hackerank-Array-NewYearChaos

    题目背景描述 新年第一天,N 个人排队坐过山车.每个人穿有带编号的衣服 \([1, 2, 3, ...]\). 因为排队时间太久,有人发现给前面相邻的人喂一颗糖,就可以和他交换位置,而每人手里只有两颗 ...

  4. React Native 【学习总结】-【常用命令】

    前言 刚接触RN,相信很多人无从下手,不知道下一步要干什么,能干什么,本次学习围绕这个问题,将RN的常用命令总结一下,帮助你快速上手 架构理解 光知道命令的作用,远远不够,如果知道命令背后的意义,才能 ...

  5. Oracle数据库拼音首字母模糊搜索

    1.建立函数 CREATE OR REPLACE FUNCTION F_PINYIN(P_NAME IN VARCHAR2) RETURN VARCHAR2 AS V_COMPARE ); V_RET ...

  6. 20162328蔡文琛 Java课程总结

    20162328 2016-2017-2<程序设计与数据结构>课程总结 一.每周作业.结对编程博客的链接汇总 预备作业01 20162328:表达对专业的期许.浅谈师生关系.对未来学习任务 ...

  7. TensorFlow:NameError: name ‘input_data’ is not defined

    在运行TensorFlow的MNIST实例时,第一步 import tensorflow.examples.tutorials.mnist.input_data mnist = input_data. ...

  8. UVALive - 6916 Punching Robot Lucas+dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/96344 Punching Robot Time Limit: 1000MS64bit IO Format: ...

  9. 0511团队项目2.0--产品product backlog

    介绍Scrum之product backlog Scrum的基本概念其实并不复杂,但是想做好并不容易,大家都知道product backlog的重要性,但是我们如何制定和展现它,如何评定优先级,如何进 ...

  10. lintcode-201-线段树的构造

    201-线段树的构造 线段树是一棵二叉树,他的每个节点包含了两个额外的属性start和end用于表示该节点所代表的区间.start和end都是整数,并按照如下的方式赋值: 根节点的 start 和 e ...