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. 对字符串'//*[@]/div/p/a[1]/c[2]/a[3]/b'从右向左依次删除指定字符串

    import re s='//*[@]' a=s+'/div/p/a[1]/c[2]/a[3]/b' c=[1,2] b=a.split(s) #切割 c=b[1].split('/') #切割 d= ...

  2. linux中的alias命令详解

    功能说明:设置指令的别名.语 法:alias[别名]=[指令名称]参 数 :若不加任何参数,则列出目前所有的别名设置.举    例 :ermao@lost-desktop:~$ alias       ...

  3. 利用GitHub+Node.js+Hexo搭建个人博客

    本篇是自己在搭建Hexo博客平台时的一个过程记录.(2019.9.13实测有效) GitHub 账号注册 因为此文所搭建的个人博客是基于GitHub平台服务的,所以首先是注册GitHub,当然已有账号 ...

  4. JavaScript基础04——数组的创建及方法

    数组的概念及定义 数组的概念:         一组数据,数据的组和         哪些数据的组和,只要是数据(所有数据),就可以放在数组中 数组的意义:         可以同时操作多个数据 数组 ...

  5. windbg自行下载的sos.dll存放路径“..\SOS_x86_x86_4.7.3132.00.dll\5B5543296ee000\”里的“5B5543296ee000”是什么?

    问题的引出 我在调试某个崩溃问题时,要跟踪clr的栈,于是,我先执行了指令.loadby sos clrjit,没有报错,然后我又执行!clrstack,结果却有如下输出:0:000:x86> ...

  6. 后台增删改查的实现——java基础、jsp、servlet、数据库

    1.前台和后台的关系: 后台是由工作人员操作的,通过后台系统对数据库实行增删改查等操作,通过前台系统访问数据库,将数据库中的信息通过前台显示. 2.功能实现: (1)显示全部商品信息: home.js ...

  7. zeebe 0.20.0 集群部署试用

    zeebe 0.20.0 是生产可用的第一个版本,同时也有好多变动,以下是一个简单集群的运行以及一个简单 的运行说明 环境准备 docker-compose 文件   version: "3 ...

  8. vscode vue文件格式化没效果

    在vscode 中   格式化vue文件没效果 解决办法: 点击头部文件 >首选项>设置 在右侧加入这两句 "vetur.format.defaultFormatter.js&q ...

  9. async、await总结

    一.async用法 async作为一个关键字放到函数前面,用于表示函数是一个异步函数.异步函数也就意味着该函数的执行不会阻塞后面代码的执行. 异步函数语法很简单,就是在函数前面加上async 关键字, ...

  10. 表单提交 curl和浏览器方式

    表单被提交时,每个表单域都会被Url编码之后才在被发送. 浏览器每次向服务器发送url时,会进行编码,然后web服务器再进行解码. 所以,理论上,curl模拟登陆时,所传参数都必须urlencode一 ...