C - Heavy Transportation && B - Frogger(迪杰斯变形)
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
Input
Output
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
思路:
这一道题就是说假如从a到b的路有好几条,在每条路上都要过几个路口,路口与路口之间的有一个标量的意思就是过这条路的最大质量是多少。。那就是说
求出来这一条路上面的最小值,只有小于等于这个值的货物才能通过这条路到达终点。。
但是要注意从a到b的路有可能不止一条,所以我们就要去求所有能到达终点每条路的最小值,再在最小值中取最大值
解决这道题的方法:选择迪杰斯方法的变形,具体实现就是给那个记录单源最短路长度的数组全部赋值为0,再把起点的距离设为无穷大,放入优先队列中
在每一次的判断d[终点]<min(d[起点],从起点到终点边的距离)
还要注意的是在使用优先队列的优先也发生了变化,我们是求每一条路上边的最小值,最后在所有的情况中取最大值
所以说我们要求的是最大值,这就和最短路不一样了,因此我们要改变优先级
代码如下:
//终于A了。。。
//原来这一道题优先队列的优先也和最短路的不一样,因为这是要求出来每一条路的最小边,
//在在众多边进行对比找出来那个最大的。那么在刚开始对与七点相连的边进行一次遍历之后
//就要找出来d中最大的值,再从他开始遍历。。。。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int MAX=;
const int INF=0xffffff;
int n,m,d[MAX],dis[MAX];
struct shudui1
{
int start,value;
bool operator <(const shudui1 q)const
{
return value<q.value;
}
}str1;
struct shudui2
{
int start,value;
}str2;
priority_queue<shudui1>r;
vector<shudui2>w[MAX];
void JK()
{
memset(dis,,sizeof(dis));
while(!r.empty())
{
str1=r.top();
r.pop();
int x=str1.start;
if(dis[x]) continue;
dis[x]=;
int len=w[x].size();
for(int i=;i<len;++i)
{
str2=w[x][i];
if(!dis[str2.start] && d[str2.start]<min(d[x],str2.value))
{
str1.value=d[str2.start]=min(d[x],str2.value);
str1.start=str2.start;
r.push(str1);
}
}
}
}
int main()
{
int t,k=;
scanf("%d",&t);
while(t--)
{
k++;
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
{
w[i].clear();
}
memset(d,,sizeof(d));
while(m--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
str2.start=y;
str2.value=z;
w[x].push_back(str2);
str2.start=x;
w[y].push_back(str2);
}
d[]=INF;
str1.start=;
str1.value=INF;
r.push(str1);
JK(); printf("Scenario #%d:\n",k);
printf("%d\n\n",d[n]);
}
return ;
}
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input
Output
Sample Input
2
0 0
3 4 3
17 4
19 4
18 5 0
Sample Output
Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
这一道题与上面那一道题刚好相反
这一道题就是求出来从起点到终点的每一条路上面的边的最大值,和上一个差不多,这个也有好几条路,但是这个要在所有路中求最小值(花里胡哨)
这个对前期数组处理要把数组初始化为无穷大,那个起点是初始化为0
其他按照正常最短路就可以过
代码如下:
//这一道题难受死我了,这个问题我也是醉了。。。
//题意:
//青蛙一是第一个输入的数据
//青蛙而是第二个
//由于从青蛙一到青蛙二的路有好几条,青蛙一也可以直接蹦到青蛙二的位置
//所以要求这几条路中他们各自的蹦跳的最大值
//在在这几条路中的最大值中求最小值。。。。。<_>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct shudui1
{
int start;
double value;
bool operator < (const shudui1 e)const
{
return value>e.value;
}
}str1;
struct shudui2
{
int start;
double value;
}str2;
struct shudui3
{
double x,y;
}m[];
vector<shudui2>w[];
priority_queue<shudui1>r;
const double INF=0xffffff;
double v[];
int dis[];
int a,s,d,k=;
void JK()
{
//vis[1]=0;
while(!r.empty())
{
str1=r.top();
r.pop();
int x=str1.start;
double y=str1.value;
// if(v[x]<y)
// {
// // printf("****\n");
// continue;
// }
if(dis[x]) continue;
dis[x]=;
int len=w[x].size();
//printf("%d %d \n",len,str1.start);
for(int i=;i<len;++i)
{
str2=w[x][i];
// printf("%d %d %d %d\n",v[str2.start],v[x],str2.value,str2.start);
if(v[str2.start]>max(v[x],str2.value)) // 做题方法大致不变,但是v中存的值要改变,假比
// v[2]中原来值为2-------是青蛙一直接蹦了过去
// 但是从青蛙一蹦到三号点距离为1.414,再从三号点蹦到二号点2--3--->距离:1.414
// 此时大都青蛙二的路有两条
// 1--->2;
// 1--->3---->2,三中存的是一到三的最大值,到二的时候比较的时侯,v[3]就代表之前所有者一条路上的最大边,
// 此时他的value是三道二这条边的长度,这样就相当于二中存的是1到2这条路上的边的最大值
// 之后赋值给二的时候,如果二中有值,就代表这是其他路到二位值的最大值,再次赋值时要比较
{
// printf("******\n");
v[str2.start]=max(v[x],str2.value);
//v[str2.start]=v[x]+str2.value;
str1.start=str2.start;
str1.value=v[str2.start];
r.push(str1);
}
}
}
}
int main()
{
while(~scanf("%d",&a))
{
k++;
if(a==) break;
memset(dis,,sizeof(dis));
//memset(vis,0x3f,sizeof(vis));
// for(int i=1;i<=a;++i)
// {
// vis[i]=INF;
// }
for(int i=;i<=a;++i)
v[i]=INF;
for(int i=;i<=a;++i)
{
scanf("%lf%lf",&m[i].x,&m[i].y);
}
double q;
for(int i=;i<a;++i)
{
for(int j=i+;j<=a;++j)
{
//if((i==1 && j==2) || (i==2 && j==1)) continue;
//if(i==j) continue;
q=sqrt((m[i].x-m[j].x)*(m[i].x-m[j].x)+(m[i].y-m[j].y)*(m[i].y-m[j].y));
str2.start=j;
str2.value=q;
w[i].push_back(str2);
str2.start=i;
w[j].push_back(str2);
//printf("%d %d %lf\n",i,j,q);
}
}
// printf("%d %d\n",w[1][0].start,w[1].size());
v[]=;
str1.start=;
str1.value=;
r.push(str1);
JK();
printf("Scenario #%d\n",k);
printf("Frog Distance = %.3lf\n",v[]);
//r.clear();
for(int i=;i<=a;++i)
w[i].clear();
printf("\n");
}
return ;
}
C - Heavy Transportation && B - Frogger(迪杰斯变形)的更多相关文章
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- poj1797 - Heavy Transportation(最大边,最短路变形spfa)
题目大意: 给你以T, 代表T组测试数据,一个n代表有n个点, 一个m代表有m条边, 每条边有三个参数,a,b,c表示从a到b的这条路上最大的承受重量是c, 让你找出一条线路,要求出在这条线路上的最小 ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ1797 Heavy Transportation —— 最短路变形
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- poj 1797 Heavy Transportation(最短路径Dijkdtra)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 26968 Accepted: ...
- Heavy Transportation(最短路 + dp)
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- 将root 当成arraylist放入数据sturts2 入门笔记
刚启动idea 就报出错误 [-- ::,] Artifact -sturts2:war exploded: Error during artifact deployment. See server ...
- 「洛谷5300」「GXOI/GZOI2019」与或和【单调栈+二进制转化】
题目链接 [洛谷传送门] 题解 按位处理. 把每一位对应的图都处理出来 然后单调栈处理一下就好了. \(and\)操作处理全\(1\). \(or\)操作处理全\(0\). 代码 #include & ...
- spring AOP的概念和使用
指路:http://www.cnblogs.com/liujiayun/p/5912628.html AOP的来源:OOP在一些重复代码的使用中,代码冗余比较多,利用AOP可以改善. 通过编写切面和切 ...
- Python学子之如何退出python 命令行
python命令行是新手学习python过程中必须要学的一个工具,下面我们来看一下怎么退出python命令行. 工具/原料 python2.7 方法/步骤 1.我们这里使用的是python3.6版本, ...
- 如何在Linux中使用命令行卸载软件
您可以使用“dpkg”命令来查看您的计算机,按“Ctrl + Alt + T”的所有已安装包的列表,打开一个终端窗口. 在提示符下键入以下命令,然后按Enter键.dpkg -- list 要卸载程序 ...
- JavaEEspring整理
Spring框架—控制反转(IOC) 1 Spring框架概述 1.1 什么是Spring 1.2 S ...
- Event filter with query "SELECT * FROM __InstanceModi
Event filter with query "SELECT * FROM __InstanceModi 问题描述: Details -Event filter with quer ...
- linux下安装kubectl
查看所有版本: https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG.md 下载指定版本: curl -O https://dl ...
- 新版本的Python问题
1.在print方面,新版本需要加括号,调用函数时也是如此,比如: import string s='the quick brown fox jumped to the lazy dog' print ...
- java 根据经纬度坐标计算两点的距离算法
/** * @Desc 根据经纬度坐标计算两点的距离算法<br> * @Author yangzhenlong <br> * @Data 2018/5/9 18:38 */ p ...