Description

Input

Output

Sample Input

10 4974
3636 3
6679 70
7182 93
10618 98
14768 23
15242 99
16077 35
23368 46
27723 15
32404 81

Sample Output

0.465308

Hint

题解

典型的 $01$ 分数规划。

我们假设 $x[]$ 中和 $a[]$ 中只保存了选取的点。

依题,要求 $$ans={{\sum_i {\sqrt{|x[i]-x[i-1]-l|}}} \over {\sum_i a[i]}}$$

按照 $01$ 分数规划的套路,我们假设有对于当前值更优的解。

$$\begin{aligned}ans&\geq{{\sum_i {\sqrt{|x[i]-x[i-1]-l|}}} \over {\sum_i a[i]}}\\ans\times{\sum_i a[i]}&\geq{\sum_i {\sqrt{|x[i]-x[i-1]-l|}}}\\{\sum_i ({ans\times a[i]})}&\geq{\sum_i {\sqrt{|x[i]-x[i-1]-l|}}}\\0&\geq{\sum_i {\sqrt{|x[i]-x[i-1]-l|}}}-{\sum_i ({ans\times a[i]})}\\0&\geq{\sum_i ({\sqrt{|x[i]-x[i-1]-l|}-ans\times a[i]})}\end{aligned}$$

那么我们去二分这个 $ans$,每次做一次 $\text{DP}$ 判断有无更优解即可。

 //It is made by Awson on 2017.9.19
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Abs(a) ((a) < 0 ? (-(a)) : (a))
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int INF = ~0u>>;
const int N = ;
const double eps = 1e-; int n, l;
int x[N+], a[N+]; bool judge(double r) {
double f[N+];
f[] = ;
for (int i = ; i <= n; i++) {
f[i] = INF;
for (int j = ; j < i; j++)
f[i] = min(f[i], f[j]+sqrt(Abs(x[i]-x[j]-l))-r*a[i]);
}
return f[n] < eps;
}
void work() {
for (int i = ; i <= n; i++)
scanf("%d%d", &x[i], &a[i]);
double L = , R = 1e9;
while (R - L > eps) {
double mid = (L+R)/.;
if (judge(mid)) R = mid;
else L = mid;
}
printf("%.6lf\n", L);
} int main() {
freopen("line.in", "r", stdin);
freopen("line.out", "w", stdout);
while (~scanf("%d%d", &n, &l))
work();
return ;
}

[测试题]line的更多相关文章

  1. linux测试题

    http://www.2cto.com/os/201307/225399.html  2013最新linux运维面试题 在对linux基本知识的归纳总结之后,这里是一份linux的测试题.希望能帮助大 ...

  2. JavaScript中的基础测试题

                                                                                                    Java ...

  3. ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id

    出现场景:当点击"分类"再返回"首页"时,发生error退出   BUG描述:Caused by: java.lang.IllegalArgumentExcep ...

  4. Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.

    启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...

  5. 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容

    我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...

  6. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  7. Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"

    同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...

  8. [LeetCode] Line Reflection 直线对称

    Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given ...

  9. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

随机推荐

  1. 20162323周楠《Java程序设计与数据结构》第八周总结

    20162323周楠 2016-2017-2 <程序设计与数据结构>第八周学习总结 教材学习内容总结 一个异常是一个对象,它定义了并不轻易出现的或是错误的情形 异常由程序或运行时环境抛出, ...

  2. Tornado websocket应用

    应用场景 WebSocket 的特点如下 适合服务器主动推送的场景(好友上线,即时聊天信息,火灾警告,股票涨停等) 相对于Ajax和Long poll等轮询技术,它更高效,不耗费网络带宽和计算资源 它 ...

  3. Cypher语法

    cypher是neo4j官网提供的声明式查询语言,非常强大,用它可以完成任意的图谱里面的查询过滤,我们知识图谱的一期项目 基本开发完毕,后面会陆续总结学习一下neo4j相关的知识.今天接着上篇文章来看 ...

  4. DML数据操作语言之查询(二)

    当我们查询出了N条记录之后 ,我们知道一共是几条记录,或者这些记录某一字段(列值)的最大值,最小值,平均值等,就可以使用聚合函数. 1.聚合函数 聚合函数会将null 排除在外.但是count(*)例 ...

  5. ruby:TypeError: 对象不支持此属性或方法

    解决办法. 1.下载对应版本 下载node.js,根据ruby版本决定下载32还是x64,我的ruby版本x64 https://npm.taobao.org/mirrors/node/v8.9.3/ ...

  6. Jmeter读取文件中的值《一》

    此篇主要是对应上一章节的呼应,上一篇中讲到将返回值写入文件,这个值如果在下一个接口中用到, 那么我们需要去从文件中读取数据,这是我们该如何操作? 一.测试计划中添加CSV Data Set Confi ...

  7. EasyUI中DataGrid隔行改变背景颜色。

    <table id="dg" class="easyui-datagrid" style="width: 1000px; height: 300 ...

  8. Python内置函数(50)——issubclass

     英文文档: issubclass(class, classinfo) Return true if class is a subclass (direct, indirect or virtual) ...

  9. redis入门(02)redis的常见问题

    一.常见问题 1.安装遇到/bin/sh: cc: command not found 解决办法:安装gcc yum install gcc 2.后台启动server端 2.1.问题现象 2.2.解决 ...

  10. ELK学习总结(3-3)elk的组合查询

    1.bool 查询: must: 必须 should:  可以满足,也可以不满足. must_not: minimum_should_match: 至少要x个匹配才算匹配成功 disable_coor ...