题目连接:http://poj.org/problem?id=2253

题意:给出一个无向图,求一条1~2的路径使得路径上的最大边权最小.

分析:dij将距离更新改成取最大值即可,即dp[i]表示到达i点过程中的最大边权,更新后可能多个,再靠优先队列取出最小的最大边权。

不过好像精度问题,我的代码C++能AC,但G++就不能。

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 100000000
#define inf 0x3f3f3f3f
#define eps 1e-9
#define N 1010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PII pair<int,int>
using namespace std;
struct node
{
int v;
double w;
node(){}
node(int v,double w):v(v),w(w){}
bool operator<(const node &a)const
{
return w>a.w;
}
};
double dp[N];
int vis[N],n;
vector<node>g[N];
double dij()
{
priority_queue<node>que;
while(!que.empty())que.pop();
for(int i=;i<=n;i++)dp[i]=1e9;
FILL(vis,);
node cur,nxt;
cur.v=;cur.w=;
dp[]=;
que.push(cur);
while(!que.empty())
{
cur=que.top();que.pop();
int x=cur.v;
if(vis[x])continue;
vis[x]=;
for(int i=,sz=g[x].size();i<sz;i++)
{
nxt=g[x][i];
int v=nxt.v;double w=nxt.w;
if(max(dp[x],w)<dp[v])
{
dp[v]=max(dp[x],w);
que.push(node(v,dp[v]));
}
}
}
return dp[];
}
int x[],y[];
double dist(int a,int b,int x,int y)
{
return sqrt(1.0*(a-x)*(a-x)+1.0*(b-y)*(b-y));
}
int main()
{
int cas=;
while(scanf("%d",&n)&&n)
{
for(int i=;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
g[i].clear();
}
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
{
double d=dist(x[i],y[i],x[j],y[j]);
g[i].push_back(node(j,d));
g[j].push_back(node(i,d));
}
printf("Scenario #%d\n",cas++);
printf("Frog Distance = %.3lf\n\n",dij());
}
}

poj2253(最短路小变形)的更多相关文章

  1. poj1797(最短路小变形)

    题目连接:http://poj.org/problem?id=1797 题意: 分析:dp[i]表示到达i点的过程中的最大承受重量,更新到i点时可能有多条路径,由优先队列堆出最大的那条即可. #inc ...

  2. POJ-2253-Frogger +最短路小变形

    传送门:http://poj.org/problem?id=2253 参考:https://www.cnblogs.com/lienus/p/4273159.html 题意:给出一个无向图,求一条从 ...

  3. POJ-2253 Frogger---最短路变形&&最大边的最小值

    题目链接: https://vjudge.net/problem/POJ-2253 题目大意: 青蛙A想访问青蛙B,必须跳着石头过去,不幸的是,B所在的石头太远了,需要借助其他的石头,求从A到B的路径 ...

  4. poj2253 最短路变形

    题目连接:http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of a ...

  5. POJ 1797-Heavy Transportation-dijkstra小变形和POJ2253类似

    传送门:http://poj.org/problem?id=1797 题意: 在起点和终点间找到一条路,使得经过的边的最小值是最大的: 和POJ2253类似,传送门:http://www.cnblog ...

  6. POJ-2253(最短路变形+dijikstra算法+求解所有路径中所有最长边中的一个最小值)

    frogger POJ-2253 这题的代码特别像prim求解最小生成树的代码,其实两者本来也很像. 这里的d数组不再维护的起点到该点的最短距离了,而是路径中的最长距离. #include<io ...

  7. UVA 12661 Funny Car Racing 有趣的赛车比赛(最短路,变形)

    题意:赛道有n个交叉点,和m条单向路径(有重边),每条路都是周期性关闭的,且通过仍需一段时间.在比赛开始时,所有道路刚好打开,选择进入该道路必须满足“在打开的时间段进入,在关闭之前出来”,即不可在路上 ...

  8. UVALive 4128 Steam Roller 蒸汽式压路机(最短路,变形) WA中。。。。。

    题意: 给一个由n*m个正方形格子组成的矩形,其中每个格子的边都是可以走的,长度给定,规定:如果在进入该路前需要拐弯,或者走完该路需要拐弯,都是需要付出双倍距离的(每条路最多算2倍).问从起点到终点的 ...

  9. DAG求最短路--TSP变形--状压dp

    DAG状压dp的一种 题目: $m$个城市,$n$张车票,第i张车票上的时间是$t_i$, 求从$a$到$b$的最短时间,如果无法到达则输出“impossible” 解法: 考虑状态:“现在在城市$v ...

随机推荐

  1. Tomcat 乱码设置

    如果表单是以get方式提交就会出现中文乱码这时可以在tomcat中配置解决中文乱码问题. 方法如下:在tomcat的conf文件夹下的conf中找到server.xml文件 找到 Connector ...

  2. Cloudera Hadoop 5& Hadoop高阶管理及调优课程(CDH5,Hadoop2.0,HA,安全,管理,调优)

    1.课程环境 本课程涉及的技术产品及相关版本: 技术 版本 Linux CentOS 6.5 Java 1.7 Hadoop2.0 2.6.0 Hadoop1.0 1.2.1 Zookeeper 3. ...

  3. Magento给产品添加“new”或者折扣数量标签 magento new label. discount label

    文章最底部有效果图. 给新产品添加“new”的标签.给折扣产品,显示出折扣的数量. 这个可以自己写一段代码加在到模板文件夹下面的catalog/product/list.phtml中. 以下是代码 & ...

  4. 你以为在用SharePoint但事实上不是

    博客地址 http://blog.csdn.net/foxdave 原文链接:http://www.techrepublic.com/blog/tech-decision-maker/you-thin ...

  5. Visio中添加、移动或删除形状上的连接点的方法

    Visio中添加.移动或删除形状上的连接点的方法 利用Visio画图时,学会使用连接点能使你的画图质量和速度大幅度提高.下面在Visio2010中,以一个例子讲述如何使用连接点. 一. 准备 1. 打 ...

  6. the least common multiplier

    Description There are many unsolvable problem in the world.It could be about one or about zero.But t ...

  7. spring mvc3中的addFlashAttribute方法

    spring mvc3中的addFlashAttribute方法  

  8. POJ2031Building a Space Station (最小生成树之prim)

    Problem Description You are a member of the space station engineering team, and are assigned a task ...

  9. Android手机便携式wifi的使用及无线数据传输(主要针对XP系统)

    适用条件: 1.可以上网的安卓系统2.2以上的智能手机,或有便携式wifi功能的安卓智能手机 2.有无线网卡的笔记本电脑或台式机(特别是XP系统) 测试手机:中兴U930 电脑:华硕K50系列笔记本 ...

  10. D7升级时候发现许多System函数和网络函数只有Byte版本的,需要注意

    SetLength 对于字符串,是WideChar的长度GetMem 只针对ByteMove 只针对ByteFillChar 只针对ByteWriteFile(API) 只针对Byte SetSock ...