2547: Repairing a Road

时间限制: 1 Sec  内存限制: 128 MB

提交: 3  解决: 2

题目描述

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.

Input

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 xiyi (1<=xiyi<=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.

Output

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 21 2 1.5 1.82 3 2.0 1.52 11 2 2.0 1.80 0

样例输出

2.5891.976

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = 110;
const int MAXE = 1010;
const double EPS = 1e-6;
inline int sgn(double x)
{
if(fabs(x) < EPS) return 0;
return x > 0 ? 1 : -1;
}
double fpai(double t, double v, double a)
{
return 1 - log(a) * v * pow(a, - t);
}
inline void update_min(double &a, const double &b)
{
if(a > b) a = b;
}
double mat[MAXN][MAXN];
int x[MAXE], y[MAXE];
double v[MAXE], a[MAXE];
int n, m;
void floyd()
{
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j) update_min(mat[i][j], mat[i][k] + mat[k][j]);
}
double find_t(int i, int x, int y, double l, double r)
{
double L = l, R = r;
while(R - L > EPS)
{
double mid = (L + R) / 2;
if(fpai(mid, v[i], a[i]) > 0) R = mid;
else L = mid;
}
if(sgn(fpai(L, v[i], a[i])) != 0) return l;
return L;
}
double solve()
{
double t, ans = mat[1][n];
for(int i = 0; i < m; ++i)
{
t = find_t(i, x[i], y[i], mat[1][x[i]], ans);
update_min(ans, t + v[i] * pow(a[i], -t) + mat[y[i]][n]);
t = find_t(i, y[i], x[i], mat[1][y[i]], ans);
update_min(ans, t + v[i] * pow(a[i], -t) + mat[x[i]][n]);
}
return ans;
}
int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
if(n == 0 && m == 0) break;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j) mat[i][j] = 1e5;
mat[i][i] = 0;
}
for(int i = 0; i < m; ++i)
{
int aa, bb;
double cc;
scanf("%d%d%lf%lf", &aa, &bb, &cc, &a[i]);
x[i] = aa;
y[i] = bb;
v[i] = cc;
update_min(mat[aa][bb], cc);
update_min(mat[bb][aa], cc);
}
floyd();
printf("%.3f\n", solve());
}
}

YTU 2547: Repairing a Road的更多相关文章

  1. 湖南省第6届程序大赛 Repairing a Road

    Problem G Repairing a Road You live in a small town with R bidirectional roads connecting C crossing ...

  2. UVA 11883 Repairing a Road(最短路径+暴力枚举)

    You live in a small town with R bidirectional roads connecting C crossings and you want to go from c ...

  3. 【CodeForces 567E】President and Roads(最短路)

    Description Berland has n cities, the capital is located in city s, and the historic home town of th ...

  4. Codeforces Round #Pi (Div. 2) E. President and Roads tarjan+最短路

    E. President and RoadsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567 ...

  5. Codeforces Round #Pi (Div. 2) ABCDEF已更新

    A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  6. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛) H XOR

    链接:https://www.nowcoder.com/acm/contest/116/H来源:牛客网 题目描述 Once there was a king called XOR, he had a ...

  7. 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- XOR(二进制使用)

    链接:https://www.nowcoder.com/acm/contest/116/H来源:牛客网 题目描述 Once there was a king called XOR, he had a ...

  8. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)

    http://poj.org/problem?id=3216 Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Su ...

随机推荐

  1. spring的IOC的简单理解

    之前看了一下源码,看的挺吃力,只能是慢慢看了. 简单说一下springIOC的我的理解,IOC也叫控制反转,可以有效的减低各个组件之间的耦合度 想象一下,如果不用IOC,那么系统里面会有大量的new ...

  2. LeetCode(49)Group Anagrams

    题目 Given an array of strings, group anagrams together. For example, given: ["eat", "t ...

  3. Vue如何使用vue-area-linkage实现地址三级联动效果

    很多时候我们需要使用地址三级联动,即省市区三级联动.网上有很多插件,在此介绍Vue的一款地区联动插件:vue-area-linkage,下面介绍如何使用这个插件实现地址联动效果:         1. ...

  4. dva使用及项目搭建

    一.简介 本文将简单分析dva脚手架的使用及项目搭建过程. 首先,dva是一个基于redux和redux-saga的数据流方案,然后为了简化开发体验,dva还额外内置了react-router和fet ...

  5. 【XML】-- C#读取XML中元素和属性的值

    Xml是扩展标记语言的简写,是一种开发的文本格式. 啰嗦几句儿:老师布置的一个小作业却让我的脑细胞死了一堆,难的不是代码,是n多嵌套的if.foreach,做完这个,我使劲儿想:我一女孩,没有更多女孩 ...

  6. Webdriver测试脚本2(控制浏览器)

    Webdriver提供了操作浏览器的一些方法,例如控制浏览器的大小.操作浏览器前进和后退等. 控制浏览器窗口大小 有时候我们希望能以某种浏览器尺寸打开,让访问的页面在这种尺寸下运行.例如可以将浏览器设 ...

  7. 九度oj 题目1182:统计单词

    题目1182:统计单词 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4780 解决:1764 题目描述: 编一个程序,读入用户输入的,以“.”结尾的一行文字,统计一共有多少个单词,并分别 ...

  8. poj 1733离散化(map)+并查集

    http://blog.sina.com.cn/s/blog_803d08c00100y2yy.html #include<stdio.h> #include<iostream> ...

  9. bzoj4553 [Tjoi2016&Heoi2016]序列 树状数组(区间最大值)+cqd

    [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1006  Solved: 464[Submit][ ...

  10. 【BZOJ3669】魔法森林(LCT)

    题意:有一张无向图,每条边有两个权值.求选取一些边使1和n连通,且max(a[i])+max(b[i])最小 2<=n<=50,000 0<=m<=100,000 1<= ...