Problem G

Repairing a Road

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 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.

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.

Sample Input

Output for the Sample Input

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

题意:给C个顶点(从1开始编号), R条边, 的无向图. 其中每条边上有起点, 终点, 时间权值vi, 和另一参数ai。如果这道路总共修了t时间,那么这条路的花费就会变成 vi * ai ^ (-t)。我们要从1走到C,求最小花费(花费就是时间)。

思路: 先用floyd把每两点间的最短距离算出, 判断出这俩点是否相通,如果相通的话,暴力枚举每条可以用于节省时间的边。

 #include <iostream>
#include <cmath>
#include <cstdio>
#define LL long long
#include <cstring>
#define INF 100000000000
#include <queue>
#define eps (1e-6) using namespace std;
typedef struct edge
{
LL from,to;
double v,a;
}edge;
double cost[][];//floyd,cost 用于存储两点间的最短路
queue<edge> que;//用于暴力枚举每一条两点间的最短边
LL N,R;//N,R分别是顶点和边的数目
double sum;
void init()
{
while (!que.empty())
que.pop();
for (int i=;i<=N;i++)
{
for(int j=;j<=N;j++)
{
if (i==j)
cost[i][j]=;
else
cost[i][j]=INF;
}
}
}
void input()
{
edge e;
LL temp;
for (int i=;i<=R;i++)
{
scanf("%I64d %I64d %lf %lf",&e.from,&e.to,&e.v,&e.a);
if (e.v<cost[e.from][e.to])
cost[e.from][e.to]=e.v;//无向图,双向边
if (e.v<cost[e.to][e.from])
cost[e.to][e.from]=e.v;//不考虑修路效果情况下,最短路由e.v构成
que.push(e);
temp=e.from;
e.from=e.to;
e.to=temp;
que.push(e);
}
}
void floyd()
{
for (int k=;k<=N;k++)
{
for (int i=;i<=N;i++)
{
for (int j=;j<=N;j++)
{
cost[i][j]=min(cost[i][k]+cost[k][j],cost[i][j]);
}
}
}
}
void solve()
{
edge e;
double limit;//记录对于每条边递增函数的起点
while (!que.empty())
{
e=que.front();que.pop();
if (abs(e.a-)>eps)//防止出现除零错误
limit=log(e.v*log(e.a))/log(e.a);
else //数学计算:y = t + v*a^(-t); => y'=1+(-v*a^(-t)ln(a))=0; => a^t=v*ln(a); => t=log(a,v*ln(a))=log(e,v*ln(a))/log(e,a);
limit=;
if (cost[][e.from]<limit)
{ //sum = min( min(1->e.from) + f(e.from,e.to) + min(e.to->N) ) e:所有可能的边,考虑方向,所以e入队时做了处理
if (limit+e.v*pow(e.a,-limit)+cost[e.to][N] < sum)
sum=limit+e.v*pow(e.a,-limit)+cost[e.to][N];
}
else
{
limit=cost[][e.from];
if (limit+e.v*pow(e.a,-limit)+cost[e.to][N] < sum)
sum=limit+e.v*pow(e.a,-limit)+cost[e.to][N];
}
}
}
int main()
{
while (scanf("%I64d%I64d",&N,&R)==&&(R||N))
{
init();
input();
floyd();
sum=cost[][N];
solve();
printf("%.3lf\n",sum);
}
return ;
}

湖南省第6届程序大赛 Repairing a Road的更多相关文章

  1. 湖南省第6届程序大赛第6题 Biggest Number

    Problem F Biggest Number You have a maze with obstacles and non-zero digits in it: You can start fro ...

  2. csu 1503: 点弧之间的距离-湖南省第十届大学生计算机程序设计大赛

    这是--比量p并用交点连接中心不上弧.在于:它至p距离.是不是p与端点之间的最短距离 #include<iostream> #include<map> #include< ...

  3. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:  2016-0 ...

  4. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 原文章网页 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:   ...

  5. 摹客 · Veer 第二届设计大赛邀你来战!

    2018年12月,摹客设计大赛一年一度一归来. 继2017年摹客全国首届原型设计大赛成功举办后,本次大赛是摹客第二届设计大赛.大赛由摹客主办,Veer独家冠名赞助,iSlide和创客贴协办,国内多家知 ...

  6. 湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)

    Biggest Number 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero di ...

  7. 湖南省第十三届大学生计算机程序设计竞赛 Football Training Camp 贪心

    2007: Football Training Camp[原创-转载请说明] Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 1 ...

  8. YTU 2547: Repairing a Road

    2547: Repairing a Road 时间限制: 1 Sec  内存限制: 128 MB 提交: 3  解决: 2 题目描述 You live in a small town with R b ...

  9. 湖南省第六届大学生程序设计大赛原题 F Biggest Number (UVA1182)

    Biggest Number http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30851#problem/F 解题思路:DFS(检索)+BF ...

随机推荐

  1. Python 字符串正则处理实例

    #coding:utf-8 ''' Created on 2017��9��6�� @author: li.liu ''' from selenium import webdriver from se ...

  2. Zookeeper基础入门介绍

    什么Zookeeper Zookeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization).命 ...

  3. onreadystatechange和onload区别分析

    onreadystatechange和onload区别分析   script加载 IE的script 元素只支持onreadystatechange事件,不支持onload事件. FireFox,Op ...

  4. axure快速上手

    Axure RP是一个专业的快速原型设计工具.Axure(发音:Ack-sure),代表美国Axure公司:RP则是Rapid Prototyping(快速原型)的缩写.Axure RP是美国Axur ...

  5. map_multimap

    #include<iostream> #include<string> #include<map> using namespace std; struct Self ...

  6. python高性能编程 读书笔记

    GIL 确保 Python 进程一次只能执行一条指令 ====分析工具cProfile 分析函数耗时line_profiler  逐行分析 heapy 追踪 Python 内存中所有的对象— 这对于消 ...

  7. canvas绚丽的随机曲线

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyMAAAHECAIAAAClb2KBAAAgAElEQVR4nOyd+VsaV/v/Pz/UpW3abJ ...

  8. mssql 清理死锁

    -存储过程 我们可以使用以下存储过程来检测,就可以查出引起死锁的进程和SQL语句.SQL Server自带的系统存储过程sp_who和sp_lock也可以用来查找阻塞和死锁, 但没有这里介绍的方法好用 ...

  9. 9、Hadoop配置文件和HDFS垃圾回收

    配置文件 默认配置文件:相对应的jar包中 core-default.xml hdfs-default.xml yarn-default.xml mapred-default.xml 自定义配置文件 ...

  10. VSFTPD匿名用户上传文件

    1.安装vsftpd yum -y install vsftpd yum -y install ftp 客户端 2.编写配置文件 vim /etc/vsftpd/vsftpd.conf anonymo ...