[uva] 10099 - The Tourist Guide
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的更多相关文章
- UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...
- 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 ...
- CodeForces 589H Tourist Guide
传送门 题目大意 给定$n$个点$m$条边的无向图,有$K$个关键点,你要尽可能的让这些关键点两两匹配,使得所有点对之间可以通过简单路径连接且任意两个简单路径没有重复的边(可以是共同经过一个点),输出 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- uva 10048 Audiophobia(最小生成树)
题目链接:10048 - Audiophobia 题目大意:有n个城市,和m条街道,每条街道有一个噪音值,q次去问,从城市a到城市b,路径上分贝值的最大值最小为多少. 解题思路:与uva 10099的 ...
- UESTC-888-Absurdistan Roads(kruskal+floyd)
The people of Absurdistan discovered how to build roads only last year. After the discovery, every c ...
随机推荐
- 向指定url发送请求与获取响应
string url = @"https://www.baidu.com"; //向指定服务器发起请求 HttpWebRequest request = (HttpWebReque ...
- js获取字符串字节的位数
ifSubUser.getBlength = function(str){ ;i--;){ n += str.charCodeAt(i) > ? : ; } return n; }
- Oracle 数据库管理员及管理员的作用
以下测试实例均在Oracle11gr2下测试!!! 一.简介:每个Oracle数据库应该至少有一名数据库管理员(dba),对于一个小的数据库,一个dba就够了,但是对于一个大的数据库,可能需要多个db ...
- MySQL表级约束和列级约束
对一个数据列建立的约束,称为列级约束 对多个数据列建立的约束,称为表级约束 列级约束即可以在列定义时生命,也可以在列定义后声明. 表级约束只能在列定义后声明. NOT NULL和DEFAULT只存在列 ...
- KOA 与 CO 实现浅析
KOA 与 CO 的实现都非常的短小精悍,只需要花费很短的时间就可以将源代码通读一遍.以下是一些浅要的分析. 如何用 node 实现一个 web 服务器 既然 KOA 实现了 web 服务器,那我们就 ...
- 如何使标签a处于不可用状态
今天做项目的时候突然发现a标签下用disabled无法使它的点击事件失效(貌似ie下可以,没有测试过), 首先说一下项目要求,点击a标签(点击之后以防多次快速点击,这里需要点击后使标签a实现),触发a ...
- StringUtils 中 isEmpty 和 isBlank 的区别
在项目的工作学习中经常用到了 apache commons 中的 StringUtils 的 isBlank 和 isEmpty 来判断字符串是否为空,这个方法都是判断字符串是否为空做判断的,以至于 ...
- PHP的parse_ini_file()函数,解释结构类型php.ini格式的文件
1.直接读取,返回一维数组 如: "test.ini" 的内容: [names] me = Robert you = Peter [urls] first = "http ...
- 使用NDK编译含JNI的Android项目常见问题解决方案
有时候,自己下载的或者拷贝过来的JNI项目出现莫名错误,通常是找不到头文件,可能解决方案如下: Removing the C nature: The only way I could find to ...
- 【c++】构造函数初始化列表中成员初始化的次序性
上代码 #include <iostream> using namespace std; class A { public: A(int v): j(v + 2), i(j) {} voi ...