Poj 1797 Heavy Transportation ( 最短路变形

解决如何从起点到终点寻找路径,使能运输的货物重量最大。通过改进的迪杰斯特拉算法实现,适用于城市规划中街道承重限制场景。

Heavy Transportation

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

题意

要从城市1到城市N运送货物,有M条道路,每条道路都有它的最大载重量,问从城市1到城市N运送最多的重量是多少。

题解:

可以看成最短路模型 不过松弛条件需要改下
我们就需要去选取离源点权值最大的点,使得它的该路径的最大载重量大一些;

AC代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define CLR(a,b) memset(a,(b),sizeof(a))

const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
const int N = 1e3+10;
int  mps[N][N];       //邻接矩阵,表示从->的距离
int dis[N];       //dst[i] 从到i的距离
bool vis[N];      // 标记节点是否被访问
int n, m;

void init()
{
    for(int i = 1; i <= n; i++) {
        for(int j = 1;j <= n; j++) mps[i][j] = -1;
    }
}

void Dijkstra(int s)
{
    CLR(vis,false);
    for(int i = 1;i <= n; i++) {
        dis[i] =  mps[s][i];
    }
    vis[s] = true;
    int minx;
    int k;
    for(int i = 1; i <= n; i++){
        minx = -1;
        for(int j = 1; j <= n; j++) {
            if(!vis[j] && dis[j]>minx) {
                minx = dis[j];
                k = j;
            }
        }
        vis[k] = true;
        for(int j = 1;j <= n; j++) {
            if(!vis[j] && mps[j][k]!=-1) {
                if(dis[j] == -1) dis[j] = min(mps[k][j],dis[k]);
                else dis[j] = max(dis[j],min(dis[k],mps[k][j]));
            }
        }
    }
}
int main()
{
    int zz = 0;
    int T;
    scanf("%d",&T);
    while(T--) {
        scanf("%d%d",&n,&m);
        init();
        for(int i = 1;i <= m; i++) {
            int x, y, z;
            scanf("%d%d%d",&x,&y,&z);
            mps[x][y] = mps[y][x] = z;
        }
        Dijkstra(1);
        printf("Scenario #%d:\n",++zz);
        printf("%d\n",dis[n]);
        printf("\n");
    }

return 0;
}
下载前可以先看下教程 https://pan.quark.cn/s/a426667488ae 标题“仿淘宝jquery图片左右切换带数字”揭示了这是一个关于运用jQuery技术完成的图片轮播机制,其特色在于具备淘宝在线平台普遍存在的图片切换表现,并且在整个切换环节中会展示当前图片的序列号。 此类功能一般应用于电子商务平台的产品呈现环节,使用户可以便捷地查看张商品的照片。 说明中的“NULL”表示未提供进一步的信息,但我们可以借助标题来揣摩若干核心的技术要点。 在构建此类功能时,开发者通常会借助以下技术手段:1. **jQuery库**:jQuery是一个应用广泛的JavaScript框架,它简化了HTML文档的遍历、事件管理、动画效果以及Ajax通信。 在此项目中,jQuery将负责处理用户的点击动作(实现左右切换),并且制造流畅的过渡效果。 2. **图片轮播扩展工具**:开发者或许会采用现成的jQuery扩展,例如Slick、Bootstrap Carousel或个性化的轮播函数,以达成图片切换的功能。 这些扩展能够辅助迅速构建功能完善的轮播模块。 3. **即时数字呈现**:展示当前图片的序列号,这需要通过JavaScript或jQuery来追踪并调整。 每当图片切换时,相应的数字也会同步更新。 4. **CSS美化**:为了达成淘宝图片切换的视觉效果,可能需要设计特定的CSS样式,涵盖图片的排列方式、过渡效果、点状指示器等。 CSS3的动画和过渡特性(如`transition`和`animation`)在此过程中扮演关键角色。 5. **事件监测**:运用jQuery的`.on()`方法来监测用户的操作,比如点击左右控制按钮或自动按时间间隔切换。 根据用户的交互,触发相应的函数来执行...
垃圾实例分割数据集 一、基础信息 • 数据集名称:垃圾实例分割数据集 • 图片数量: 训练集:7,000张图片 验证集:426张图片 测试集:644张图片 • 训练集:7,000张图片 • 验证集:426张图片 • 测试集:644张图片 • 分类类别: 垃圾(Sampah) • 垃圾(Sampah) • 标注格式:YOLO格式,包含实例分割的边形点坐标,适用于实例分割任务。 • 数据格式:图片文件 二、适用场景 • 智能垃圾检测系统开发:数据集支持实例分割任务,帮助构建能够自动识别和分割图像中垃圾区域的AI模型,适用于智能清洁机器人、自动垃圾桶等应用。 • 环境监控与管理:集成到监控系统中,用于实时检测公共区域的垃圾堆积,辅助环境清洁和治理决策。 • 计算机视觉研究:支持实例分割算法的研究和优化,特别是在垃圾识别领域,促进AI在环保方面的创新。 • 教育与实践:可用于高或培训机构的AI课程,作为实例分割技术的实践数据集,帮助学生理解计算机视觉应用。 三、数据集优势 • 精确的实例分割标注:每个垃圾实例都使用详细的边形点进行标注,确保分割边界准确,提升模型训练效果。 • 数据样性:包含种垃圾物品实例,覆盖不同场景,增强模型的泛化能力和鲁棒性。 • 格式兼容性强:YOLO标注格式易于与主流深度学习框架集成,如YOLO系列、PyTorch等,方便研究人员和开发者使用。 • 实际应用价值:直接针对现实世界的垃圾管理需求,为自动化环保解决方案提供可靠数据支持,具有重要的社会意义。
POJ 1797是一道经典的图论题目,题目名称为“Heavy Transportation”。这道题目主要考察的是大生成树算法,特别是Kruskal算法或Prim算法。以下是该题目的简要介绍和解决思路: ### 题目描述 给定一个无向图,图中有N个节点和M条边。每条边都有一个重量。你的任务是找到一条从节点1到节点N的路径,使得路径上小重量的边尽可能大。 ### 输入格式 第一行包含一个整数T,表示测试用例的数量。 每个测试用例的第一行包含两个整数N和M,分别表示节点的数量和边的数量。 接下来的M行,每行包含三个整数A, B和C,表示节点A和节点B之间有一条重量为C的边。 ### 输出格式 对于每个测试用例,输出一行,包含一个整数,表示从节点1到节点N的路径上小重量的边的大可能值。 ### 解题思路 1. **小生成树(Kruskal算法)**:我们可以将问题转化为求小生成树的大边权。由于我们需要找到从节点1到节点N的路径上小重量的边尽可能大,因此我们可以对所有边按重量从大到小排序,然后依次加入图中,直到节点1和节点N连通为止。 2. **Prim算法**:我们也可以使用Prim算法来解决这个问题。Prim算法是从一个起始节点开始,逐步扩展生成树,每次选择与当前生成树相连的小边,直到所有节点都被包含在生成树中。 ### 示例代码(Kruskal算法) ```java import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { static int[] parent; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); for (int t = 1; t <= T; t++) { int N = scanner.nextInt(); int M = scanner.nextInt(); Edge[] edges = new Edge[M]; for (int i = 0; i < M; i++) { edges[i] = new Edge(scanner.nextInt(), scanner.nextInt(), scanner.nextInt()); } Arrays.sort(edges, new Comparator<Edge>() { @Override public int compare(Edge e1, Edge e2) { return e2.weight - e1.weight; } }); parent = new int[N + 1]; for (int i = 1; i <= N; i++) { parent[i] = i; } int result = 0; for (Edge edge : edges) { if (find(edge.u) == find(edge.v)) continue; union(edge.u, edge.v); if (find(1) == find(N)) { result = edge.weight; break; } } System.out.println("Scenario #" + t + ":"); System.out.println(result); System.out.println(); } scanner.close(); } static int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } static void union(int x, int y) { parent[find(x)] = find(y); } static class Edge { int u, v, weight; Edge(int u, int v, int weight) { this.u = u; this.v = v; this.weight = weight; } } } ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值