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 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...
随机推荐
- ActiveX控件获取不到对象属性或者方法的原因分析
1.找不到调用的DLL或程序: 2.调用控件方法名称,与定义的函数名称不符合: 3.如果是网站网页调用ActiveX,检查控件是否添加安全对象: 4.如果是网站网页调用ActiveX,检查网页是否加入 ...
- org.mybatis.spring.transaction.SpringManagedTransaction - JDBC Connection [********] will not be managed by Spring
如下图,查看层次是否正确.
- 09CSS高级定位
CSS高级定位 定位方式——position position:static|absolute|relative static表示为静态定位,是默认设置. absolute表示绝对定位,与下位置属 ...
- 第2节 mapreduce深入学习:4, 5
第2节 mapreduce深入学习:4.mapreduce的序列化以及自定义排序 序列化(Serialization)是指把结构化对象转化为字节流. 反序列化(Deserialization)是序列化 ...
- django显示图片
dirctory vickey_django vickey(projectname) vickey __init__.py __pycache__ settings.py urls.py wsgi.p ...
- sphinx配置
配置文件 ## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,p ...
- centos7搭建安装sentry
Sentry 是一款基于 Django实现的错误日志收集和聚合的平台,它是 Python 实现的,但是其日志监控功能却不局限于python,对诸如 Node.js, php,ruby, C#,java ...
- day 21 03 补全异常处理
day 21 03 异常处理(补全) 1.异常处理的整体几个语句: try: .......#有可能出错的代码 ret=int(input('number >>>')) print ...
- 集训第六周 数学概念与方法 UVA 11181 条件概率
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...
- js给<img>的src赋值问题
原生JS:document.getElementById("imageId").src = "xxxx.jpg";jquery:$("#imageId ...