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. Leetcode 28——Implement strStr()

    Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle ...

  2. 设计模式NO.2

    设计模式NO.2 本次博客内容为第二次设计模式的练习.根据老师的要求完成下列题目: 题目1 如果需要开发一个跨平台视频播放器,可以在不同操作系统平台(如Windows.Linux.UNIX等)上播放多 ...

  3. 201621123025《Java程序设计》第二周学习总结

    1.本周学习总结 以几个关键词描述本周的学习内容.并将关键词之间的联系描述或绘制出来. 答:java的两种数据类型:基本数据类型和引用数据类型:==与equals的区别:动态数组. 2.书面作业 1. ...

  4. 201421123042 《Java程序设计》第12周

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...

  5. Binary Tree Xorder Traversal

     * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeN ...

  6. 2018年东北农业大学春季校赛-wyh的吃鸡

    BFS: 1. 从起点开始BFS,遇到X点则return: 2. vis[px][py][0]代表经过pxpy这点前还没有找到车: vis[px][py][1]代表经过pxpy这点前已经找到车: 3. ...

  7. STM32读取温湿度传感器DHT11和DHT21(AM2301)系列问题

    1.DHT11和DHT21传感器 这两种传感器都是奥松公司的产品,具体的传感器说明书在其官网上有(www.aosong.com). DHT11 数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合 ...

  8. wordpress | WP Mail SMTP使用QQ邮箱发布失败的解决办法

    在使用contact form 7插件时遇到邮件发送失败的问题,经过检查发现是因为服务器不支持mail()函数,判断是否支持mail()函数可以参考http://www.diyzhan.com/201 ...

  9. Extensions in UWP Community Toolkit - FrameworkElement Extensions

    概述 UWP Community Toolkit Extensions 中有一个为FrameworkElement 提供的扩展 - FrameworkElement Extensions,本篇我们结合 ...

  10. CentOS7下安装python-pip

    一.检查是否已经安装 检查linux有没有安装python-pip包,直接执行:: yum install python-pip 二.安装 pip install 1.没有python-pip包就执行 ...