E. Hiking
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness equals bi. The traveler will move down the river in one direction, we can assume that he will start from point 0 on the coordinate axis and rest points are points with coordinates xi.

Every day the traveler wants to cover the distance l. In practice, it turns out that this is not always possible, because he needs to end each day at one of the resting points. In addition, the traveler is choosing between two desires: cover distance l every day and visit the most picturesque places.

Let's assume that if the traveler covers distance rj in a day, then he feels frustration , and his total frustration over the hike is calculated as the total frustration on all days.

Help him plan the route so as to minimize the relative total frustration: the total frustration divided by the total picturesqueness of all the rest points he used.

The traveler's path must end in the farthest rest point.

Input

The first line of the input contains integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 105) — the number of rest points and the optimal length of one day path.

Then n lines follow, each line describes one rest point as a pair of integers xi, bi (1 ≤ xi, bi ≤ 106). No two rest points have the same xi, the lines are given in the order of strictly increasing xi.

Output

Print the traveler's path as a sequence of the numbers of the resting points he used in the order he used them. Number the points from 1 to n in the order of increasing xi. The last printed number must be equal to n.

Sample test(s)
input
5 9
10 10
20 10
30 1
31 5
40 10
output
1 2 4 5 
贴一篇博客http://blog.csdn.net/hhaile/article/details/8883652 原文作者没有找到。
上面的博客看了之后,此题就是一道水水的 二分 + DP 了。
 #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const int maxn = ;
int pos[maxn],b[maxn],pre[maxn],n,l;
double dp[maxn];
double check(double x)
{
memset(pre,,sizeof(pre));
for (int i = ; i <= n; i++)
{
dp[i] = inf;
for (int j = ; j < i; j++)
{
double tmp = dp[j] + sqrt(abs(. + pos[i] - pos[j] - l)) - x * b[i];
if (tmp < dp[i])
{
dp[i] = tmp;
pre[i] = j;
}
}
}
return dp[n];
}
void print_path(int x)
{
if (pre[x])
print_path(pre[x]);
printf("%d ",x);
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while (~scanf ("%d%d",&n,&l))
{
for (int i = ; i <= n; i++)
scanf ("%d%d",pos+i,b+i);
double ua = ,ub = 1e10;
while (ub - ua > eps)
{
double mid = (ua + ub)/;
if (check(mid) >= )
ua = mid;
else
ub = mid;
}
print_path(n);
}
return ;
}

Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)的更多相关文章

  1. Codeforces Round #277.5 (Div. 2) ABCDF

    http://codeforces.com/contest/489 Problems     # Name     A SwapSort standard input/output 1 s, 256 ...

  2. Codeforces Round #277.5 (Div. 2)

    题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...

  3. Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud A. SwapSort time limit per test    1 seco ...

  4. Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being

    http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...

  5. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  6. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

  7. Codeforces Round #277.5 (Div. 2)-A. SwapSort

    http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...

  8. Codeforces Round #277.5 (Div. 2)-D

    题意:求该死的菱形数目.直接枚举两端的点.平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2. 代码: #include< ...

  9. Codeforces Round #277.5 (Div. 2)B——BerSU Ball

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 【Unity3D自我记录】解决NGUI通过问题触发事件点

    在虚拟现实的游戏开发或当,人们功能操作,人们走一下地面行动.但随后点击界面button什么时候,会不会触发click事件.这是通过点.当然,点击界面button当相同的触发点接地运行操作,样也是点透 ...

  2. OleDb 读取 excel

    //定义变量 _Application ExcelApp; Workbooks wbsMyBooks; _Workbook wbMyBook; Worksheets wssMysheets; _Wor ...

  3. Android - Broadcast机制

    以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luosheng ...

  4. ZOJ2099

    题意:给多个点,连成折线,求一个矩形可以包含这条折线. 输入: 多组测试数据 多个点的坐标 每组测试数据以0,0结束 以0,0结束程序 输出: 矩形左下角和右上角的坐标 思路:水题,注意输入那里有点坑 ...

  5. C#里巧用DateTime预设一些可选的日期范围(如本年度、本季度、本月等)

    //大家在做报表或查询的时候都会有给用户预设一些可选的日期范围(如上图)                //如本年度销售额.本季度利润.本月新增客户                //C#里内置的Da ...

  6. Redis,MemCached,MongoDB 概述

    调研项目主要有Redis. MemCached. MongoDB,以及Amazon的DynamoDB Redis 是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key- ...

  7. Android 5.1 Camera 架构学习之Camera初始化

    Android Camera 采用C/S架构,client 与server两个独立的线程之间(CameraService)使用Binder通信. 一 CameraService的注册. 1.手机开机后 ...

  8. php视图操作

    一.视图的基本介绍          视图是虚拟的表.与包含数据的表不一样,视图只包含使用时动态检索数据的查询.         使用视图需要MySQL5及以后的版本支持.         下面是视图 ...

  9. new date() 函数在浏览器中的兼容问题!!

    引言: 同一种语言javascript,在不同的浏览器中,存在语言兼容性问题,本质上是由于不同的浏览器是支持的语言标准和实现上各有差异.本文将基于new Date来创建Date对象来分析这个问题. v ...

  10. Qt Quick App的两种启动模式

    QQmlApplicationEngine搭配Window QQuickView搭配Item 两者不同之处在于: 使用QQuickView显示QML文档,对窗口的控制权(比如设置窗口标题.Icon.窗 ...