HDU 1569 find the safest road
来源:互联网 发布:mac可以玩跑跑卡丁车吗 编辑:程序博客网 时间:2024/06/11 09:24
这道题用Floyd和dijkstra均可以解出。
将各条路径的成绩值维护一下即可,也可以对各条路上的权值取对数,这样所有的路都变成了负值。找乘积的最大值,也就是找负值的最大值即可,贴出第一种方法的AC代码:
#include<iostream>#include<stdio.h>using namespace std;double safe[1010][1010];//double map[1010][1010];int n;void floyd(){ for(int k = 0 ; k < n;k++) for(int i = 0 ; i < n;i++) for(int j = 0 ; j < n;j++) if(safe[i][k]*safe[k][j] > safe[i][j]) safe[i][j] = safe[i][k]*safe[k][j];}int main(){ while(~scanf("%d",&n)) { for(int i = 0 ; i < n;i++) for(int j = 0 ; j< n;j++) { scanf("%lf",&safe[i][j]); } floyd(); int k; scanf("%d",&k); while(k--) { int x,y; cin>>x>>y; x--,y--; if(safe[x][y]) printf("%.3lf",safe[x][y]); else printf("What a pity!"); puts(""); } } return 0;}
阅读全文
0 0
- HDU 1569 find the safest road
- [hdu]find the safest road
- hdu find the safest road
- find the safest road HDU
- find the safest road HDU
- hdu 1596 find the safest road(priority_queue )
- HDU 1596 find the safest road
- HDU-1596 find the safest road
- hdu 1596 find the safest road
- hdu 1596 find the safest road
- HDU-1596-find the safest road
- HDU 1596 find the safest road
- HDU 1596 find the safest road
- hdu 1596find the safest road--dijkstra
- hdu 1596 find the safest road
- hdu 1596 find the safest road
- hdu 1596 find the safest road
- HDU 1596 find the safest road
- 数据结构和算法分析之排序算法--插入排序篇(直接插入排序和希尔排序)
- tomcat安装与配置
- POJ 2528 Mayor's posters(加分割点)
- Android Webview 用 WebBackForwardList 来判断是否是返回的界面
- 1030. 完美数列(25)
- HDU 1569 find the safest road
- 1111. Online Map (30)
- UVA11584PartitioningByPalindromes
- Lazarus控件中控件尺寸变化的处理机制
- spring framework入门
- c语言笔记-printf()格式化输出详解
- Python爬内蒙古大学教务处并自动计算绩点(小窗体版)
- Linux下通过yum安装软件
- 链表与顺序表的区别