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. CPP链表示例

    #include<iostream> #include<stdlib.h> using namespace std; typedef struct Student_data { ...

  2. Spring 以及 Spring MVC Bean元素以及@Bean (Bean 等价于 注解 ??? 没理解错误吧)

    ①.由衷鸣谢Bossen <还是没看懂o(╥﹏╥)o><> {声明Spring Bean和注入Bean的几种常用注解和区别} Bean在Spring和SpringMVC中无所不 ...

  3. svn的使用技巧

    就是如果想一个文件在提交的时候不被上传,可以设置忽略这样提交的时候就不会被上传

  4. ajax的原理解析

    一.关于同步与异步的分析: 异步传输是面向字符的传输,它的单位是字符:而同步传输是面向比特的传输,它的单位是桢,它传输的时候要求接受方和发送方的时钟是保持一致的.而ajax就是采用的异步请求方式的. ...

  5. 20道Java面试必考题

    系统整理了一下有关Java的面试题,包括基础篇,javaweb篇,框架篇,数据库篇,多线程篇,并发篇,算法篇等等,陆续更新中.其他方面如前端后端等等的面试题也在整理中,都会有的. 注:文末有福利!pd ...

  6. mosquitto验证client互相踢

    cleint11A订阅topic#################################################### server发送topic消息 ############### ...

  7. 新概念英语(1-93)Our new neighbour

    Lesson 93 Our new neighbour 我们的新邻居 Listen to the tape then answer this question. Why is Nigel a luck ...

  8. nohup 与 & 的区别

    nohup -- invoke a utility immune to hangups : 运行命令忽略挂起信号 & 是指后台运行: nohup 的功能和& 之间的功能并不相同.其中, ...

  9. linux 安装jdk以及nginx详细过程

    一.安装jdk 1:首先下载jdk到本地,然后通过git 上传到linux服务器上 2:进入目录usr,并创建目录java,将jdk的压缩文件移动到该目录下 cd /usr mkdir java mv ...

  10. Django:(博客系统)使用使用mysql数据->后台管理tag/post/category的配置

    Django后台一般是不需要人为的去开发的,因为django已经通过配置实现哪些模块是后台需要管理,如何排序,列表展示哪些列,列显示名称,是否为空(默认值),过滤条件,分页页数,列表中哪些项可编辑等等 ...