poj1797 dijsktra变形

2024-04-28 17:18
文章标签 变形 poj1797 dijsktra

本文主要是介绍poj1797 dijsktra变形,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 

如题:http://poj.org/problem?id=1797

Heavy Transportation
Time Limit: 3000MS Memory Limit: 30000K
Total Submissions: 21783 Accepted: 5793

Description

Background
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

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4

Source

TUD Programming Contest 2004, Darmstadt, Germany

 

题意:给出一堆双向边,权值是本条路可运输的最大量。求出最大能运输多重的东西

 

思路:不难发现,一条路径最大运输量取决于这条路径的最小权值边。对dijsktra算法松弛操作进行修改。

dis[i]代表到当前顶点i的这条路径的最大承重值。


  for(j=1;j<=n;j++)
  {
   if(vis[j]) continue;
   dis[j]=MAX(dis[j],MIN(dis[k],a[k][j]));
  }

 松弛操作,理解一下就能懂。

 

 

#include<iostream>
using namespace std;
#define MAXN 1005
int a[MAXN][MAXN];
int dis[MAXN];
bool vis[MAXN];
int MAX(int a,int b)
{return a>b?a:b;}
int MIN(int a,int b)
{return a>b?b:a;}

void dij(int v,int n)
{
 memset(vis,false,sizeof(vis));
 int i,j;
 for(i=1;i<=n;i++)
  dis[i]=a[v][i];
 vis[v]=true;
 for(i=1;i<n;i++)
 {
  int temp=-1,k=v;
  for(j=1;j<=n;j++)
  {
   if(vis[j]) continue;
   if(temp<dis[j])
   {
    temp=dis[j];
    k=j;
   }
  }
  vis[k]=true;
  for(j=1;j<=n;j++)
  {
   if(vis[j]) continue;
   dis[j]=MAX(dis[j],MIN(dis[k],a[k][j]));
  }
 }
}
int main()
{
// freopen("C:\\1.txt","r",stdin);
 int N;
 cin>>N;
 int count=0;
 while(N--)
 {
  count++;
  memset(a,-1,sizeof(a));
  int n,m;
  scanf("%d %d",&n,&m);
  int i;
  for(i=1;i<=m;i++)
  {
   int t1,t2,w;
   scanf("%d %d %d",&t1,&t2,&w);
   a[t1][t2]=w;
   a[t2][t1]=w;
  }
  dij(1,n);
  printf("Scenario #%d:\n%d\n",count,dis[n]);
  printf("\n");
 }
}

 

这篇关于poj1797 dijsktra变形的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/943802

相关文章

csu(背包的变形题)

题目链接 这是一道背包的变形题目。好题呀 题意:给n个怪物,m个人,每个人的魔法消耗和魔法伤害不同,求打死所有怪物所需的魔法 #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<queue>#include<set>//#include<u>#include<map

hdu3389(阶梯博弈变形)

题意:有n个盒子,编号1----n,每个盒子内有一些小球(可以为空),选择一个盒子A,将A中的若干个球移到B中,满足条件B  < A;(A+B)%2=1;(A+B)%3=0 这是阶梯博弈的变形。 先介绍下阶梯博弈: 在一个阶梯有若干层,每层上放着一些小球,两名选手轮流选择一层上的若干(不能为0)小球从上往下移动,最后一次移动的胜出(最终状态小球都在地面上) 如上图所示,小球数目依次为

跳台阶(动态规划/斐波那契变形)

跳台阶 链接:https://www.nowcoder.com/acm/contest/90/A来源:牛客网 题目描述 小明在坐景驰科技研发的无人车到达了目的地。 景驰科技(JingChi.ai)是一家由人工智能技术驱动、以无人驾驶技术为核心的智能出行公司。它将打造面向中国市场的全无人驾驶。 从无人车下来以后,小明看到了一个长长的楼梯。 有一个n级台阶的楼梯,小明一次可以向上跳1

Bellman_Ford变形求最长路+正权回路或spfa——POJ 1860

对应POJ题目:点击打开链接 Currency Exchange Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 20814 Accepted: 7451 Description Several currency exchange points are working in our city. L

[android总结]Zxing二维码扫描图片变形

关于使用ZXing扫描二维码图片变形的问题,晚上有很多种解释,但都是一个模板,经过多种尝试,还是没能解决我的问题。于是就自己研究,不过索性解决了,再次简单分享一下。 如果想在应用里添加自己的我二维码扫描功能,可以参照:http://blog.csdn.net/xiaanming/article/details/10163203   这篇博客描述的很详尽。 首先,你应该知道

Android 图片放错位置会拉伸变形

今天做了一个很小的需求,然后需要图片,我给ui要图片。直接给了我三套,还命名 x . xx. 2k 真的一开始都不知道。没有玩过这么正规的。我就用了一张,放到了hdpi下面。 后来同事帮我才知道, 图片要放到xhdip 里面,那样才不会拉伸变形。因为我们适配的分辨率很高。 现在的分辨率都是最低720,普遍1080。 我这才知道自己过时了。 然后放到正确的文件夹下,嗯,可以正常显示了。 x

【HDU4507】【吉哥系列故事——恨7不成妻】【变形数位dp】

吉哥系列故事——恨7不成妻 Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2260    Accepted Submission(s): 660 Problem Description 单身!   依然单

android 搜索栏滑动跟随缩放和移动,缩放变形问题

这两天新版界面改版,有个页面要求搜索栏跟随滑动会位移和缩放, 心想这还不简单么,具体如下是实现好的效果:    心想这还不简单么,第一想法是用 recyclerView.addOnScrollListener 计算好Y轴移动的距离和x缩放值再根据这些算出X轴偏移位置不就ok了么。 想法总是美好的,现实总是残酷的,view自带的setScale 缩放后导致搜索栏里的文字和图片同时放大

CSS3 渐变、变形、过渡、动画小结

CSS3 渐变(IE9&-用滤镜filter来兼容) 线性渐变: linear-gradient([ [ <angle> | to <side-or-corner> ] ,]? <color-stop>[, <color-stop>]+) <side-or-corner> = [left | right] || [top | bottom]   八个方向,to bottom是默认值,相当于1

《算法竞赛进阶指南》0x26广搜变形

双端队列BFS 在最基本的广度优先搜索中,每次沿着分支的扩展都被记为“一步”。我们通过逐层搜索,解决了从起始状态到每个状态的最小步数问题。这其实等价于在一张边权均为1的图上执行广度优先遍历,求出每个点相对于起点的最短距离。,每个状态在第一次被访问并入队时,计算出的步数即为所求。 如果图上的边权不全为1呢,我们先来讨论边权要么是1,要么是0的情况。 例题 acwing175.电路维修 将每个格