317. Fast Ride

Time limit per test: 0.25  second(s) Memory limit: 65536 kilobytes
input: standard output: standard

Is there a Russian who does not like a fast ride?! Royal messenger should get from point A to point B as quickly as possible. Point A has coordinate 0 on the Ox axis. Point B has positive coordinate B on the Ox axis. Of course, the messenger will use horses to get to the destination point. The messenger is not allowed to travel by foot because of an importance of his mission and security reasons.
There are N stables on the straight line from A to B. The i-th stable has Mi horses inside. Each horse is characterized by its speed vj and maximum distance it can gallop dj (after that it falls exhausted). The messenger can change the horse reaching or passing a stable to any horse from that stable without losing time.
Your task is to find the minimum time the messenger needs to get to the point B.

Input

The first line of the input contains two integer numbers B and N (1 ≤ B ≤ 108; 1 ≤ N ≤ 5000), where N is the number of stables. Descriptions of the stables follow. The first line of each description contains two integer numbers Xi, Mi (0 ≤ Xi ≤ 108; 0 < Mi) — the position of the stable and the number of horses in this stable respectively. The following Mi lines contain the description of the horses. Each description of a horse is a pair of integer numbers vj, dj (1 ≤ vj ≤ 108; 1 ≤ dj ≤ 108). The total number of horses in all stables is no more than 105. It is possible that two or more stables have the same position.

Output

Write the minimum time which will take the messenger to get to the point B to the output. The answer should be written with no less than 3 digits after the decimal point. If the solution does not exist, write -1 to the output.

Example(s)
sample input
sample output
10 3
5 2
1 100
10 3
0 1
1 50
8 1
2 3
6.30000000

组队赛第九场 想到出来的一条DP 。

题目给了5000个驿站 , 然后每个驿站有M头马,有不同的速度还有能走的路程 。 然后问,到达B位置最少用的时间 。 马最多有10W头 。

然后用dp[i]表示到达第 i 个驿站的最小时间 。

然后 O(n) *O (Mi ) * O( n ) 枚举驿站 枚举马 枚举下一个状态 ,照过  -。-   数据都几弱下 。。

读入完数据之后要对每个驿站按距离从大到小排一下序。记录一个输入的时候的 id。然后马用个邻接链表保存就OK了~

但是条题都有几多trick。

驿站的位置可能超过B 。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; typedef long long LL; const int N = ;
const int M = ;
const double inf = 1e10; double dp[N];
double B;
int n; struct node
{
double d,v;
bool operator <( const node &a )const{
if(v != a.v )return v > a.v;
else return d > a.d;
}
}; struct node2
{
double d;
int num,id;
bool operator < (const node2 &a )const {
return d < a.d;
}
}e[N]; vector< node >g[N]; void init()
{
for( int i = ; i <= n+ ; ++i ){
dp[i]=inf;
g[i].clear();
}
dp[]=;
} int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif int v,d;
node h;
while(~scanf("%lf%d",&B,&n) ){
init(); for ( int i = ; i < n ; ++i ){
scanf("%lf%d",&e[i].d ,&e[i].num);
e[i].id = i;
for( int j = ; j < e[i].num ; ++j ){
scanf("%lf%lf",&h.v,&h.d );
g[ i ].push_back(h);
}
} e[ n ].d = B;
e[ n ].num = ;
sort( e , e + n + ); int goal = ;
bool ok = ;
for(int i = ; i <= n ;++i ){
int idx = e[i].id;
if( dp[i] >= inf ){ ok = ; break; }
if( e[i].d == B ) { goal = i; break; }
sort ( g[ idx ].begin() , g[ idx ].end() );
int glen = g[idx].size();
for( int j = ; j < glen ; ++j ){
h = g[idx][j];
for(int k = i + ; k <= n && e[k].d - e[i].d <=h.d ;++k ){
dp[k] = min(dp[k] , dp[i] + (e[k].d - e[i].d) / h.v );
}
}
} if( !ok || dp[ goal ] >= inf ) puts("-1");
else printf("%.6lf\n",dp[ goal ] ); }
return ;
}

SSOJ 317 Fast Ride的更多相关文章

  1. Fast Matrix Operations(UVA)11992

    UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...

  2. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  3. RIDE小技巧——Content Assistance快捷键(CTRL+空格)的修改

    大家在用RIDE Content Assistance功能的快捷键时会与机器中是输入法的切换相冲突,这里提供一下修改的位置,大家可以根据个人的喜好修改. 有三处需要修改: {Python_home}\ ...

  4. RIDE -- Robot Framework setup

    RobotFramework 是一款基于python 的可以实现关键字驱动和数据驱动并能够生成比较漂亮的测试报告的一款测试框架 这里使用的环境是 python-2.7.10.amd64.msi RID ...

  5. opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较

    opencv中的SIFT,SURF,ORB,FAST 特征描叙算子比较 参考: http://wenku.baidu.com/link?url=1aDYAJBCrrK-uk2w3sSNai7h52x_ ...

  6. 基于Fast Bilateral Filtering 算法的 High-Dynamic Range(HDR) 图像显示技术。

    一.引言 本人初次接触HDR方面的知识,有描述不正确的地方烦请见谅. 为方便文章描述,引用部分百度中的文章对HDR图像进行简单的描述. 高动态范围图像(High-Dynamic Range,简称HDR ...

  7. Fast RCNN 训练自己的数据集(3训练和检测)

    转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ https://github.com/YihangLou/fas ...

  8. Fast RCNN 训练自己数据集 (2修改数据读取接口)

    Fast RCNN训练自己的数据集 (2修改读写接口) 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ http ...

  9. 网格弹簧质点系统模拟(Spring-Mass System by Fast Method)附源码

    弹簧质点模型的求解方法包括显式欧拉积分和隐式欧拉积分等方法,其中显式欧拉积分求解快速,但积分步长小,两个可视帧之间需要多次积分,而隐式欧拉积分则需要求解线性方程组,但其稳定性好,能够取较大的积分步长. ...

随机推荐

  1. XSLT学习(九)通过JavaScript转化xml

    如果您的浏览器支持 XSLT,那么在浏览器中它可被用来将文档转换为 XHTML. JavaScript 解决方案 在前面的章节,我们已向您讲解如何使用 XSLT 将某个 XML 文档转换为 XHTML ...

  2. mod_jk是Apache服务器的一个可插入模块

    mod_jk简称JK,是Apache服务器的一个可插入模块,用以为Apache或IIS服务器提供处理JSP/Servlet的能力. Apache作为一款强大的Web服务器,本身缺乏处理JSP/Serv ...

  3. 2018-2-13-WPF-资源冻结

    title author date CreateTime categories WPF 资源冻结 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23:3 + ...

  4. hdu1210Eddy's 洗牌问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1210 Eddy是个ACMer,他不仅喜欢做ACM题,而且对于纸牌也有一定的研究,他在无聊时研究发现,如 ...

  5. 【LeetCode】并查集 union-find(共16题)

    链接:https://leetcode.com/tag/union-find/ [128]Longest Consecutive Sequence  (2018年11月22日,开始解决hard题) 给 ...

  6. java访问ftp

    1.连接ftp FTPClient ftpClient = new FTPClient(); ftpClient.connect(host,port); ftpClient.login(userNam ...

  7. vue新建项目之标准路由配置--父子嵌套界面

    配置路由所有用到的地方总共四步或者说四处 1.index.js(src--router--index.js) 父子界面嵌套---需要配置子路由 import Vue from 'vue' import ...

  8. bzoj4903 & loj2264 [Ctsc2017]吉夫特 Lucas 定理+状压DP

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4903 https://loj.ac/problem/2264 http://uoj.ac/pr ...

  9. bzoj1488 [HNOI2009]图的同构 Burnside 引理

    题目传送门 bzoj1488 - [HNOI2009]图的同构 bzoj1815 - [Shoi2006]color 有色图(双倍经验) 题解 暴力 由于在做题之前已经被告知是 Burnside 引理 ...

  10. vs code 使用技巧整理

    快捷键 Ctrl + Shift + F:在文件夹中搜索; Ctrl + Shift + P:命令面板; Ctrl + Shift + T:重新打开 关闭的编辑页面; Ctrl+Shift+PgUp/ ...