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}$ 判断有无更优解即可。

  1. //It is made by Awson on 2017.9.19
  2. #include <map>
  3. #include <set>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <queue>
  7. #include <stack>
  8. #include <cstdio>
  9. #include <string>
  10. #include <vector>
  11. #include <cstdlib>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. #define LL long long
  16. #define Max(a, b) ((a) > (b) ? (a) : (b))
  17. #define Min(a, b) ((a) < (b) ? (a) : (b))
  18. #define Abs(a) ((a) < 0 ? (-(a)) : (a))
  19. #define lowbit(x) ((x)&(-(x)))
  20. using namespace std;
  21. const int INF = ~0u>>;
  22. const int N = ;
  23. const double eps = 1e-;
  24.  
  25. int n, l;
  26. int x[N+], a[N+];
  27.  
  28. bool judge(double r) {
  29. double f[N+];
  30. f[] = ;
  31. for (int i = ; i <= n; i++) {
  32. f[i] = INF;
  33. for (int j = ; j < i; j++)
  34. f[i] = min(f[i], f[j]+sqrt(Abs(x[i]-x[j]-l))-r*a[i]);
  35. }
  36. return f[n] < eps;
  37. }
  38. void work() {
  39. for (int i = ; i <= n; i++)
  40. scanf("%d%d", &x[i], &a[i]);
  41. double L = , R = 1e9;
  42. while (R - L > eps) {
  43. double mid = (L+R)/.;
  44. if (judge(mid)) R = mid;
  45. else L = mid;
  46. }
  47. printf("%.6lf\n", L);
  48. }
  49.  
  50. int main() {
  51. freopen("line.in", "r", stdin);
  52. freopen("line.out", "w", stdout);
  53. while (~scanf("%d%d", &n, &l))
  54. work();
  55. return ;
  56. }

[测试题]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. Struts2学习笔记五 拦截器

    拦截器,在AOP中用于在某个方法或字段被访问之前,进行拦截,然后在之前或之后加入某些操作.拦截是AOP的一种实现策略. Struts2中,拦截器是动态拦截Action调用的对象.它提供了一种机制可以使 ...

  2. Java字符串的split(String str)方法空串的问题

    String strs[] = "SS1BB2CC3".split("\\D+"); public static String Test(){ Date d = ...

  3. New UWP Community Toolkit - RadialProgressBar

    概述 UWP Community Toolkit  中有一个圆形的进度条控件 - RadialProgressBar,本篇我们结合代码详细讲解  RadialProgressBar 的实现. Radi ...

  4. eoLinker API-Shop 抓住区块链机遇,从这些API开始

    区块链是分布式存储.点对点传输.共识机制.加密算法等计算机技术的新型应用模式.所谓共识机制是区块链系统中实现不同节点之间建立信任.获取权益的数学算法. 区块链目前分为三类: 公有区块链(PublicB ...

  5. 福州大学W班-需求分析评分排名

    作业链接 https://edu.cnblogs.com/campus/fzu/FZUSoftwareEngineering1715W/homework/1019 作业要求 1.需求文档 1) 参考& ...

  6. 2017-2018-1 1623 bug终结者 冲刺002

    bug终结者 冲刺002 by 20162329 张旭升 今日冲刺任务: 能够显示主菜单和功能 游戏需要提供主菜单让玩家进行游戏设置,同时能能够把地图文件中的信息转换成为图像显示到游戏界面上 能够实现 ...

  7. WORK

    团队展示 队伍信息 队名:小狗队 队长:刘映华(201421122021) 队员:兰运良(201421122030).郭和水(201421122017) 团队项目描述 团队项目描述是基于之前的四则运算 ...

  8. 算法第四版学习笔记之快速排序 QuickSort

    软件:DrJava 参考书:算法(第四版) 章节:2.3快速排序(以下截图是算法配套视频所讲内容截图) 1:快速排序 2:

  9. 【译】Gradle 的依赖关系处理不当,可能导致你编译异常

    文章 | Ashesh Bharadwaj 翻译 | 承香墨影 授权 承香墨影 翻译.编辑并发布 在 Android Studio 中,Gradle 构建过程对于开发者来说,很大程度上是抽象的.作为一 ...

  10. SAN LUN Mapping出错导致文件系统共享冲突,数据恢复成功

    [用户单位] 中国联通某分公司[数据恢复故障描述]    SUN 光纤存储系统,中心存储为6枚300G硬盘组成的RAID6,划分为若干LUN,MAP到不同业务的服务器上,服务器上运行SUN SOLAR ...