10099 - The Tourist Guide

题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1040

打不开的可以上国内的:http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=1080

之前使用 最小生成树的 Kruskal 算法 + 广度优先搜索

改进之后用了 用动态规划技术实现的所有节点对的最短路径问题的 Floyd-Warshall 算法,不仅代码量急剧减少,简化了逻辑

此题的坑之一:Mr.G.自己也算一个人……… 反映到代码里是63行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
 
int number_points;
int map_values[110][110];
 
void floyd()
{
    for (int a = 1; a <= number_points; a++)
    {
        for (int b = 1; b <= number_points; b++)
        {
            for (int x = 1; x <= number_points; x++)
            {
                int ax = map_values[a][x];
                int xb = map_values[x][b];
 
                int smaller = ax < xb ? ax : xb;
                if (map_values[a][b] < smaller)
                {
                    map_values[a][b] = smaller;
                }
            }
        }
    }
}
 
 
int main()
{
    int count = 1;
    int number_ways;
    scanf("%d%d", &number_points, &number_ways);
    while(number_points != 0 && number_ways != 0)
    {
        // 0. 初始化图
        for (int y = 1; y <= number_points; y++)
        for (int x = 1; x <= number_points; x++)
        {
            map_values[x][y] = 0;
        }
 
        // 1. 读取边
        for (int i = 0; i < number_ways; i++)
        {
            int x, y, values;
            scanf("%d%d%d", &x, &y, &values);
            map_values[x][y] = values;
            map_values[y][x] = values;
        }
 
        // 2. 读取起始节点和顾客数量
        int start, end, number_customer;
        scanf("%d%d%d", &start, &end, &number_customer);
 
        // 3. floyd 算法
        floyd();
 
        // 4. 获取值
        int max_value = map_values[start][end];
 
        // 5. 输出结果
        max_value--; // Mr. G. 自己也算上
 
        int remainder = number_customer % max_value;
        printf("Scenario #%d\nMinimum Number of Trips = ", count);
        if (remainder)
            printf("%d\n", number_customer / max_value + 1);
        else
            printf("%d\n", number_customer / max_value);
 
        // 6. 读取下一行数据
        scanf("%d%d", &number_points, &number_ways);
        count++;
    }
 
    return 0;
}

[uva] 10099 - The Tourist Guide的更多相关文章

  1. UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

    解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...

  2. floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253

    The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...

  3. CodeForces 589H Tourist Guide

    传送门 题目大意 给定$n$个点$m$条边的无向图,有$K$个关键点,你要尽可能的让这些关键点两两匹配,使得所有点对之间可以通过简单路径连接且任意两个简单路径没有重复的边(可以是共同经过一个点),输出 ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  6. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  7. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  8. uva 10048 Audiophobia(最小生成树)

    题目链接:10048 - Audiophobia 题目大意:有n个城市,和m条街道,每条街道有一个噪音值,q次去问,从城市a到城市b,路径上分贝值的最大值最小为多少. 解题思路:与uva 10099的 ...

  9. UESTC-888-Absurdistan Roads(kruskal+floyd)

    The people of Absurdistan discovered how to build roads only last year. After the discovery, every c ...

随机推荐

  1. jieba和文本词频统计

    ---恢复内容开始--- 一.结巴中文分词涉及到的算法包括: (1) 基于Trie树结构实现高效的词图扫描,生成句子中汉字所有可能成词情况所构成的有向无环图(DAG): (2) 采用了动态规划查找最大 ...

  2. 移动端滑动时页面惯性滑动overflow-scrolling: touch

    -webkit-overflow-scrolling:auto | touch; auto: 普通滚动,当手指从触摸屏上移开,滚动立即停止 touch:滚动回弹效果,当手指从触摸屏上移开,内容会保持一 ...

  3. url传递参数带 + ,解决办法

    修改客户端,将客户端带“+”的参数中的“+”全部替换为‍“%2B”,这样参数传到服务器端时就能得到“+”了.

  4. 文献综述十四:基于Oracle11g的超市进销存管理系统设计与实现

    一.基本信息 标题:基于Oracle11g的超市进销存管理系统设计与实现 时间:2016 出版源:技术创新 文件分类:对数据库的研究 二.研究背景 为超市设计开发的超市管理系统,采用的是 VC+ Or ...

  5. css :before 内容左边 分割线(四)

    商品 左边分割线,使用css伪类实现,before or  after <style> *{ margin:; padding:; } .clearfix { *zoom:; } .cle ...

  6. spark第十一篇:spark-submit命令支持选项

    [root@linux-node3 bin]# ./spark-submit --help Usage: spark-submit [options] <app jar | python fil ...

  7. Cook-Torrance光照模型

    Cook-Torrance光照模型将物体粗糙表面看作由很多微平面组成,每一个微平面都可以看成一个理想的镜面反射体,物体表面粗糙程度由微平面斜率的变化来表示.越粗糙的表面由斜率变化越大,反之越小. Co ...

  8. Derby的jar说明

    Derby的jar说明 Derby的下载后,解压发现lib中有很多jar包,下面说明一下每个jar包的用途: 引擎库 derby.jar是引擎库,必须的 For embedded databases. ...

  9. 基于URL权限拦截的实现

    一.实现原理 1.实现原理   本示例采用SpringMVC的拦截器来实现一个基于URL的权限拦截. 2.权限管理流程 二.数据库搭建 1.用户表(sys_user) (1)表结构 (2)表字段说明 ...

  10. C#笔试题-我的答案

    (1)面向对象的语言具有__继承性_性._封装性_性._多态性_性. (2)能用foreach遍历访问的对象需要实现 _ IEnumerable 接口或声明_ GetEnumerator 方法的类型. ...