UVa 821 - Page Hopping
2015-09-21 11:17
274 查看
題目:給你一個有向的地圖,求所有路徑(兩點間的最短路徑)的平均長度。
分析:圖論,最短路。利用floyd求解,然後將所有效的邊加和求平均值即可。
說明:距離700還有14題╮(╯▽╰)╭。
分析:圖論,最短路。利用floyd求解,然後將所有效的邊加和求平均值即可。
說明:距離700還有14題╮(╯▽╰)╭。
#include <cstring> #include <cstdio> int dist[101][101]; int oo = 100000001; int main() { int a, b, n, cases = 1; while (~scanf("%d%d",&a,&b) && a+b) { //initial for (int i = 0; i < 101; ++ i) for (int j = 0; j < 101; ++ j) dist[i][j] = oo; for (int i = 0; i < 101; ++ i) dist[i][i] = 0; //read data n = 0; do { dist[a][b] = 1; if (a > n) n = a; if (b > n) n = b; }while (~scanf("%d%d",&a,&b) && a+b); //floyd for (int k = 1; k <= n; ++ k) for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) if (dist[i][j] > dist[i][k] + dist[k][j]) dist[i][j] = dist[i][k] + dist[k][j]; //output int count = 0, sum = 0; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) if (dist[i][j] < oo && dist[i][j]) { sum += dist[i][j]; count ++; } printf("Case %d: ",cases ++); printf("average length between pages = %.3lf clicks\n",1.0*sum/count); } return 0; }
相关文章推荐
- 利用Dockerfile构建一个基于centos 7,包括java 8, tomcat 7,php ,mysql+mycat的镜像
- hadoop集群部署,内存,存储配置
- linux下源码安装
- 网站添加自己公司的地图(使用的百度地图)时只显示一个空白框
- Linux Tomcat日志查看实用命令
- apache 日志轮询三种方法
- Unable to open ...\tools\capture\allegro.cfg for reading
- 快速在Ubuntu下配置apache+php+mysql+phpmyadmin环境
- Linux初学——管理文件与目录(下)
- Opencv2.4.9源码分析——SURF
- Windows 8 中的 PowerShell 3.0
- Nginx 虚拟主机 VirtualHost 配置
- Apache 虚拟主机 VirtualHost 配置
- 解谜谷歌 DevOps:什么特质可以打造世界级可靠系统?
- Centos 6.4 KVM安装和配置
- d3搭建Apache服务器
- 手把手教你Linux服务器集群部署.net网站 - 让MVC网站运行起来
- tomcat最终部署项目问题---不需要项目名称
- Nginx + fail2ban 提高安全性
- 安装libevent ubuntu下