UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)
解题报告
题意:
求全部路中最大分贝最小的路。
思路:
类似floyd算法的思想。u->v能够有另外一点k。通过u->k->v来走,拿u->k和k->v的最大值和u->v比較。存下最小的值。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,q,mmap[110][110];
void floyd() {
for(int k=0; k<n; k++)
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
mmap[i][j]=min(mmap[i][j],max(mmap[i][k],mmap[k][j]));
}
int main() {
int i,j,u,v,w,k=1;
while(~scanf("%d%d%d",&n,&m,&q)) {
if(!n&&!m&&!q)break;
for(i=0; i<n; i++) {
for(j=0; j<n; j++)
mmap[i][j]=inf;
mmap[i][i]=0;
}
for(i=0; i<m; i++) {
scanf("%d%d%d",&u,&v,&w);
mmap[u-1][v-1]=mmap[v-1][u-1]=w;
}
floyd();
if(k!=1)
printf("\n");
printf("Case #%d\n",k++);
while(q--) {
scanf("%d%d",&u,&v);
if(mmap[u-1][v-1]==inf)
printf("no path\n");
else
printf("%d\n",mmap[u-1][v-1]);
}
}
return 0;
}
| Problem B: Audiophobia |
Consider yourself lucky! Consider yourself lucky to be still breathing and having fun participating in this contest. But we apprehend that many of your descendants may not have this luxury. For, as you know,
we are the dwellers of one of the most polluted cities on earth. Pollution is everywhere, both in the environment and in society and our lack of consciousness is simply aggravating the situation.
However, for the time being, we will consider only one type of pollution - the sound pollution. The loudness or intensity level of sound is usually measured in decibels and sound having intensity level
130 decibels or higher is considered painful. The intensity level of normal conversation is 6065 decibels and that of heavy traffic is 7080 decibels.
Consider the following city map where the edges refer to streets and the nodes refer to crossings. The integer on each edge is the average intensity level of sound (in decibels) in the corresponding street.

To get from crossing A to crossing G you may follow the following path: ACFG. In that case you must be capable of tolerating sound intensity as high as 140 decibels.
For the paths ABEG, ABDG and ACFDG you must tolerate respectively 90, 120 and 80 decibels of sound intensity. There are other paths, too. However, it is clear that ACFDG is the
most comfortable path since it does not demand you to tolerate more than 80 decibels.
In this problem, given a city map you are required to determine the minimum sound intensity level you must be able to tolerate in order to get from a given crossing to another.
Input
The input may contain multiple test cases.
The first line of each test case contains three integers
,
and
where Cindicates
the number of crossings (crossings are numbered using distinct integers ranging from 1 to C), Srepresents the number of streets and Q is the number of queries.
Each of the next S lines contains three integers: c1, c2 and d indicating that the average sound intensity level on the street connecting the crossings c1 and c2 (
)
is d decibels.
Each of the next Q lines contains two integers c1 and c2 (
)
asking for the minimum sound intensity level you must be able to tolerate in order to get from crossing c1 to crossing c2.
The input will terminate with three zeros form C, S and Q.
Output
For each test case in the input first output the test case number (starting from 1) as shown in the sample output. Then for each query in the input print a line giving the minimum sound intensity level (in decibels)
you must be able to tolerate in order to get from the first to the second crossing in the query. If there exists no path between them just print the line ``no path".
Print a blank line between two consecutive test cases.
Sample Input
7 9 3
1 2 50
1 3 60
2 4 120
2 5 90
3 6 50
4 6 80
4 7 70
5 7 40
6 7 140
1 7
2 6
6 2
7 6 3
1 2 50
1 3 60
2 4 120
3 6 50
4 6 80
5 7 40
7 5
1 7
2 4
0 0 0
Sample Output
Case #1
80
60
60 Case #2
40
no path
80
Miguel Revilla
2000-12-26
UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)的更多相关文章
- UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...
- UVa567_Risk(最短路)(小白书图论专题)
解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508"& ...
- UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)
解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...
- UVa563_Crimewave(网络流/最大流)(小白书图论专题)
解题报告 思路: 要求抢劫银行的伙伴(想了N多名词来形容,强盗,贼匪,小偷,sad.都认为不合适)不在同一个路口相碰面,能够把点拆成两个点,一个入点.一个出点. 再设计源点s连向银行位置.再矩阵外围套 ...
- UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...
- UVa409_Excuses, Excuses!(小白书字符串专题)
解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include < ...
- 模板C++ 03图论算法 2最短路之全源最短路(Floyd)
3.2最短路之全源最短路(Floyd) 这个算法用于求所有点对的最短距离.比调用n次SPFA的优点在于代码简单,时间复杂度为O(n^3).[无法计算含有负环的图] 依次扫描每一点(k),并以该点作为中 ...
- 正睿OI国庆DAY2:图论专题
正睿OI国庆DAY2:图论专题 dfs/例题 判断无向图之间是否存在至少三条点不相交的简单路径 一个想法是最大流(后来说可以做,但是是多项式时间做法 旁边GavinZheng神仙在谈最小生成树 陈主力 ...
- ACM/ICPC 之 最短路-Floyd+SPFA(BFS)+DP(ZOJ1232)
这是一道非常好的题目,融合了很多知识点. ZOJ1232-Adventrue of Super Mario 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...
随机推荐
- C# 實現文件壓縮-- 背景:服務器Log.txt 過多,佔用過多硬盤空間,壓縮備份后節省空間資源
1.壓縮實現代碼如下: 調用ICSharpCode.SharpZipLib.dll(free software,可以搜到源碼). 轉移指定目錄文件夾轉移到目標文件夾 壓縮目標文件夾 刪除目標文件夾 u ...
- 05CSS链接
CSS链接 链接的四种状态: • a:link - 普通的.未被访问的链接 • a:visited - 用户已访问的链接 • a:hover - 鼠标指针位于链接的上方 • a:active ...
- java实现zip,gzip,7z,zlib格式的压缩打包
本文主要介绍的是通过使用java的相关类可以实现对文件或文件夹的压缩. zlib是一种数据压缩程序库,它的设计目标是处理单纯的数据(而不管数据的来源是什么). 7z 是一种新的压缩格式,它拥有目前最高 ...
- PHP生成文档,并把数据加入文档的小案例
PHP生成文档,可以利用file_put_contents($filename, $data),其中$filename表示文档名,$data表示需要放入的数据, 若存放的是数组,这还需要使用seria ...
- eclipse包分层
方法很简单,如下图所示: 1.点击项目栏窗口的右上角的倒三角 2.选择Pachage Presentation(包呈现) 3.选择Hierarchical(分层)
- sublime text 快捷键记录
sublime常用快捷键 Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑) Ctrl+G 跳转到相应的行 Ctrl+J 合并行(已选择需要合并的多行时) Ctrl ...
- Python中的列表(5)
1.使用函数 range() 创建一个数字列表 for value in range(1,5): print(value) console: 我们发现,它并不会打印数字5,因为 range() 函数, ...
- MySql 基础 基本使用方法
安装MySQL linux安装:阿里云服务器ecs配置之安装mysqlwindows安装: 解压 管理员身份进cmd执行解压目录下的可执行文件 初始化 D:\mysql-8.0.12-winx64\m ...
- STL优先队列重载
priority_queue默认是大根堆,如果需要使用小根堆,如下 int main(){ priority_queue<int,vector<int>,greater<int ...
- numpy——基础数组与计算
In [1]: import numpy as np In [11]: # 创建数组 a = np.array([1,2,3,4,5]) In [12]: a Out[12]: array([1, 2 ...