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 ...
随机推荐
- python format() 函数
转载 https://www.cnblogs.com/wushuaishuai/p/7687728.html 正文 Python2.6 开始,新增了一种格式化字符串的函数 format() ,它增强了 ...
- MT【328】向量里的最佳逼近
已知平面向量$\overrightarrow {a},\overrightarrow {b}$满足$|\overrightarrow {a}|=4,|\overrightarrow {b}|=2$.若 ...
- css控制table间距
border-collapse: separate;border-spacing: 20px 30px; /* 水平间距 垂直间距 */
- Zabbix监控磁盘IO值
iostat取硬盘IO值. iostat -x 3 2 | grep vdb | sed -n '2p' | awk '{print $14}' 每3s取一次值,输出第二次vdb硬盘的负载值. 添加Z ...
- appache 在windows 中无法启动的测试
使用phpstudy刚启动就自动停止,排除端口被占用后,总感觉找不到好的调试方法 网上找了一些资料,这个方法不错,所以就记录了下来.最好的办法是找appache的bin目录,打开运行,输入httpd. ...
- sed命令(二)
转自:https://www.cnblogs.com/maxincai/p/5146338.html sed命令用法 sed是一种流编辑器,它是文本处理中非常有用的工具,能够完美的配合正则表达式使用, ...
- JVM垃圾回收机制概述
JVM垃圾回收机制概述 1.定义 是指JVM用于释放那些不再使用的对象所占用的内存. 2.方式 2.1引用计数(早期) 当引用程序创建引用以及引用超出范围时,JVM必须适当增减引用数.当某个对象的引用 ...
- 13、Ajax的使用
一.AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. a).AJAX = 异步 JavaScript 和 XML. b).AJAX 是一种用于创建快速动态网页的技术. 通过在后 ...
- Python+Selenium+Unittest框架使用——Selenium——模拟操作浏览器(三)
1.浏览器大小的控制 Set_window_size()是控制浏览器大小 Maximize_window()浏览器全屏显示 from selenium import webdriver #导入sele ...
- mysql基础学习
二.操作表 1.自行创建测试数据: -- 创建数据库create database practice charset utf8;-- 1.自行创建测试数据:---- 创建班级表:classcreate ...