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 ...
随机推荐
- git总结二、关于分支上——好好认识下分支是怎么回事
同样需要先来明确两件事: HEAD指针指向的是当前分支 分支(master, dev)指向的是最新的提交 一开始,git 中只有一个master分支,严格来讲,HEAD不是指向提交而是指向master ...
- MySQL之B+树索引(转自掘金小册 MySQL是怎样运行的,版权归作者所有!)
每个索引都对应一棵B+树,B+树分为好多层,最下边一层是叶子节点,其余的是内节点.所有用户记录都存储在B+树的叶子节点,所有目录项记录都存储在内节点. InnoDB存储引擎会自动为主键(如果没有它会自 ...
- Vue组件开发
在学习vue的时候,发现有很多使用vue开发的ui组件.本着学习的目的,自己也仿照Element写一些组件. 使用VuePress编写组件文档. 单元测试:karma+mocha+chai+sinon ...
- C# 中使用面向切面编程(AOP)中实践代码整洁
1. 前言 最近在看<架构整洁之道>一书,书中反复提到了面向对象编程的 SOLID 原则(在作者的前一本书<代码整洁之道>也是被大力阐释),而面向切面编程(Aop)作为面向对象 ...
- xadmin 数据添加报错: IndexError: list index out of range
报错现象 xadmin 集成到项目后进行添加数据的时候报错 具体如下 黄页 后端 具体报错定位 报错分析 点击这里 报错解决 源码 input_html = [ht for ht in super(A ...
- js的一些点
1 闭包 闭包就是说,能够读取其他函数内部变量的函数. 其实这句话我不是很明白,因为我觉得闭包的作用是: 延迟函数执行 模拟私有变量 根据第二点的描述,应该是阻止其他东西访问自身私有成员,到了这怎么变 ...
- 【Mac上的PotPlayer视频播放器】Movist Pro for Mac 2.1.2
[简介] Movist 是Mac上最好用的视频播放器之一,功能齐全,类似Windows上的PotPlayer,今天和大家分享最新的 2.1.2 中文版本,Movist 支持几乎所有常见的视频格式,包括 ...
- 解决ssh连接linux服务器速度慢
服务器端sshd配置文件 /etc/ssh/sshd_config 看是否有如下的两条配置条目 GSSAPIAuthentication no UseDNS no 如果前面带#,请把#删掉,或者新添加 ...
- Kettle中并行执行测试
整个作业截图: 设置并行方法:右键 START 组件,勾选最后一个选项: Run Next Entries In Parallel 设置aa, bb, cc, dd, ee 都是shell脚本,内容都 ...
- Angular记录(11)
开始使用Angular写页面 使用WebStorm:版本2018.3.5 官网资料 资料大部分有中文翻译,很不错 速查表:https://www.angular.cn/guide/cheatsheet ...