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 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...
随机推荐
- /etc/auto.master - automounter的主映射文件
描述(DESCRIPTION) 当机器启动自动挂载器时, autofs(8) 脚本就会查寻 auto.master 这个主映射文件.文件中的每行分别指明,一个挂载点以及与对应的需要被挂载的文件系统.通 ...
- 最后一个非零数字(POJ 1604、POJ 1150、POJ 3406)
POJ中有些问题给出了一个长数字序列(即序列中的数字非常多),这个长数字序列的生成有一定的规律,要求求出这个长数字序列中某个位上的数字是多少.这种问题通过分析,找出规律就容易解决. 例如,N!是一个非 ...
- 前端入门22-讲讲模块化 包括webstrom建立简单ES6
https://www.cnblogs.com/dasusu/p/10105433.html
- 手动配置webpack
//注:“__dirname”是node.js中的一个全局变量,它指向当前执行脚本所在的目录.const path = require('path');const webpack = require( ...
- MFC如何设置窗口最前
首先,放到最前 this->SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//使窗口总是在最前面 this->Se ...
- vue 画二维码
首先安装一下相关的插件 qrcode2 npm install --save qrcode2 然后在需要画二维码的页面引入一下 import QRCode from 'qrcode2' 最后在meth ...
- STM32——GPIO口的八种工作模式
GPIO的输入工作模式1——输入浮空模式: GPIO_Mode_IN_FLOATING =0x04 工作原理:配置完相应寄存器为此工作模式后,高低电平信号通过1处的IO口输入进去,由于寄存器配置了的缘 ...
- [转] angular2-highcharts用法详解
1. 使用npm安装angular2-highcharts npm install angular2-highcharts --save 2.主模块中引入 app.module.ts import { ...
- Shader Wave
Shader Wave 一.原理 1. 采用 UV 坐标为原始数据,生成每一条波浪线. 2. 使用 Unity 的 Time.y 作为时间增量,动态变换波形. 二.操作步骤 1. 首先使用纹理坐标生成 ...
- Android 笔记一:线性布局
建立布局 新建项目后,在如图路径下新建xml文件可以开始编辑 weight的使用 android:layout_width="0dp",或android:layout_width= ...