toj 4611 Repairing a Road

时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte
总提交: 49 测试通过:19

描述

You live in a small town with R bidirectional roads connecting C crossings and you want to go from crossing 1 to crossing C as soon as possible. You can visit other crossings before arriving at crossing C, but it’s not mandatory.

You have exactly one chance to ask your friend to repair exactly one existing road, from the time you leave crossing 1. If he repairs the i-th road for t units of time, the crossing time after that would be viai-t. It’s not difficult to see that it takes vi units of time to cross that road if your friend doesn’t repair it.

You cannot start to cross the road when your friend is repairing it.

输入

There will be at most 25 test cases. Each test case begins with two integers C and R (2<=C<=100, 1<=R<=500). Each of the next R lines contains two integers xi, yi (1<=xi, yi<=C) and two positive floating-point numbers vi and ai (1<=vi<=20,1<=ai<=5), indicating that there is a bidirectional road connecting crossing xi and yi, with parameters vi and ai (see above). Each pair of crossings can be connected by at most one road. The input is terminated by a test case with C=R=0, you should not process it.

输出

For each test case, print the smallest time it takes to reach crossing C from crossing 1, rounded to 3 digits after decimal point. It’s always possible to reach crossing C from crossing 1.

样例输入

3 2
1 2 1.5 1.8
2 3 2.0 1.5
2 1
1 2 2.0 1.8
0 0

样例输出

2.589
1.976

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>using namespace std;const double INFD = (1 << 30) + 0.1;
const double eps = 1e-6;
const int MAX_VERTEX = 100 + 5;// 邻接矩阵,cost数组,存储两点间最短路
double cost[MAX_VERTEX][MAX_VERTEX];
// 顶点数,边数
int C, R;
struct edge {// 起点,终点int stat, ed;// 权值,一个因子double v, a;
};
// 存放边的信息,用于在修路之后,更新最短距离
queue<edge> edges;
// 1 -> C的最短路长度
double ans;// 初始化队列和邻接矩阵
void init() {while(!edges.empty()) {edges.pop();}for (int i = 1; i <= C; i++) {for (int j = 1; j <= C; j++) {if (i == j) {cost[i][j] = 0;} else {cost[i][j] = INFD;}}}
}// floyd算法求两点间的最短路径
void floyd() {for (int k = 1; k <= C; k++) {for (int i = 1; i <= C; i++) {for (int j = 1; j <= C; j++) {cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);}}}
}// 修一条路更新最短路求1->C的最短距离
void update() {while (!edges.empty()) {edge e = edges.front();edges.pop();// 记录从1到该边始点的最短时间double time = 0;// 已知v*a^(-t)// 如果a无限接近0的话,t的最小值为0// 否则按如下公式计算if (abs(e.a - 1) > eps) {// 公式计算过程// y = t + v*a^(-t) => y' = 1 + (-v*a^(-t)ln(a)) = 0// => a^t = v*ln(a) => t = log(a, v*ln(a))// => t = ln(v*ln(a))/ln(a)time = log(e.v * log(e.a)) / log(e.a);}// 取1->e.stat这条路径的最短距离time = max(time, cost[1][e.stat]);// ans = min(min(1->e.stat) + f(e.stat, t.to) + min(e.ed->N))ans = min(ans, time + e.v * pow(e.a, -time) + cost[e.ed][C]);}
}int main() {while (scanf("%d%d", &C, &R) == 2 && (C || R)) {// 初始化init();// 输入并加入边队列// input();for (int i = 0; i < R; i++) {edge e;scanf("%d%d%lf%lf", &e.stat, &e.ed, &e.v, &e.a);// 无向图cost[e.stat][e.ed] = e.v;cost[e.ed][e.stat] = e.v;edges.push(e);swap(e.stat, e.ed);edges.push(e);}// 求出未修路的最短距离floyd();ans = cost[1][C];update();//solve();printf("%.3lf\n", ans);}return 0;
}

toj 4611 Repairing a Road相关推荐

  1. Repairing a Road NBUT - 1465

    枚举每条边,那么耗费时间就是dis(1, x) + (t - dis(1, x)) + vi * ai ^ (-t) + dis(y, C) ,dis代表u到v的最短路,可知因为是最短路,1到u和v到 ...

  2. 国庆七天乐 Day7

    今天做的是湖南省2010年省赛题,悲催的只出了四题...今年省赛堪忧! 先做Codeforce去了... A:汽水瓶 有这样一道智力题:"某商店规定:三个空汽水瓶可以换一瓶汽水.小张手上有十 ...

  3. 车道检测--VPGNet: Vanishing Point Guided Network for Lane and Road Marking Detection and Recognition

    VPGNet: Vanishing Point Guided Network for Lane and Road Marking Detection and Recognition ICCV2017 ...

  4. 语义分割--Efficient Deep Models for Monocular Road Segmentation

    Efficient Deep Models for Monocular Road Segmentation code: https://lmb.informatik.uni-freiburg.de/P ...

  5. The Road to learn React书籍学习笔记(第三章)

    代码详情 声明周期方法 通过之前的学习,可以了解到ES6 类组件中的生命周期方法 constructor() 和 render() constructor() 构造函数只有在组件实例化并插入到 DOM ...

  6. TOJ 1702.A Knight's Journey

    2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http:// ...

  7. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

  8. 程序员成功之路 ——The road ahead for programmer(转引)

    一.我很羡慕在座的各位同学,因为你们是中国未来的程序员,而我不是,我一直很遗憾. 比 尔盖茨曾经写过一本书叫做<未来之路>The road ahead, 那么今天我选择这样一个题目, th ...

  9. BZOJ 2752: [HAOI2012]高速公路(road)

    2752: [HAOI2012]高速公路(road) Time Limit: 20 Sec  Memory Limit: 128 MB Submit: 1346  Solved: 499 [Submi ...

最新文章

  1. FileUpload生成图片水印,文字水印(转载)
  2. 2018 百越杯 pwn(format WriteUp)
  3. java 不退出_Java项目不挂断运行,即当账户退出或终端关闭时,程序仍然运行,并附上执行脚本...
  4. 软件测试的左移方法(译)
  5. 上班族的10大经典哲学,还有什么能难倒你?[轉自太平洋電腦網]
  6. python中global 和 nonlocal 的作用域
  7. 熊猫数据集_用熊猫掌握数据聚合
  8. java7最后战线_我的世界最后战线2.0整合包
  9. Android系统(121)---Android启动页黑屏及最优解决方案
  10. 崛起于Springboot2.X之redis集群搭建(17)
  11. python数据结构剑指offer-从尾到头打印链表
  12. 【maven】Controller层参数如何设置传null
  13. openssl lhash 数据结构哈希表
  14. C3之text属性的补充
  15. (Codeforces800Div2)B. Paranoid String(思维/动态规划)
  16. java程序员工资调查_程序员真实调查,工资真的高吗?
  17. java 文件下载示例_文件下载示例代码(JAVA)
  18. 超声波测距实现距离预警(米斯琪+开发板)
  19. 基于python的今日头条文章抓取内含signature算法
  20. 2014计算机考研分数线,2014年全国统计算机考研各个大学录取分数线汇总.doc

热门文章

  1. 04737 c++ 自学考试2019版 第六章课后练习 程序设计题 1
  2. Flutter mac 环境搭建 最简教程
  3. 【Python】汉诺塔问题
  4. 【Python】 基础语法
  5. django模型查询_如何在Django中编写有效的视图,模型和查询
  6. github在线执行_什么是Github操作,如何自动执行测试和Slack通知?
  7. 145_Power BI Report Server自定义Form登录
  8. 129_Power PivotPower BI DAX不同维度动态展示动态坐标轴
  9. Java多线程:线程停止
  10. Python 告诉你疫情扩散有多可怕