[测试题]line
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的更多相关文章
- linux测试题
http://www.2cto.com/os/201307/225399.html 2013最新linux运维面试题 在对linux基本知识的归纳总结之后,这里是一份linux的测试题.希望能帮助大 ...
- JavaScript中的基础测试题
Java ...
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- 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 ...
- 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容
我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- [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 ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
随机推荐
- 201621123050 《Java程序设计》第10周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1. 常用异常 结合题集题目7-1回答 1.1 自己以前编写的代码中经常出现 ...
- 201621123043《java程序设计》第五周学习总结
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 接口. Comparable接口 .Comparator接口.compareTo. 1.2 尝试使用思维导图将这些关键词组织起来 ...
- exports
暴露函数 var bar = require("./bar.js"); var msg = "你好"; var info = "呵呵"; f ...
- CPP链表示例
#include<iostream> #include<stdlib.h> using namespace std; typedef struct Student_data { ...
- maven(二)创建工程
创建动态Web工程打war包 File→new→Maven Project→勾上create a simple project→然后next> 然后会报一下的错 解决 创建jav ...
- 通过URL传递PDF名称参数显示PDF
1 <%@ page language="java" import="java.util.*,java.io.*" 2 pageEncoding=&quo ...
- java:多层文件夹情况下,判断文件夹下是否有文件夹,并获取到没有文件夹的名字的方法
业务问题案例 在公司遇到的一个问题,本以为很小很好解决,没想到花了一下午时间.图给的是文件路径,page1下有10个文件夹,每个有的有文件夹或者文件,要求得到page1下(即:123456789,10 ...
- Sudoku 第一步
看到这个问题的思路是先解决生成数独生成器的编写,然后再解决数独求解的问题.最开始第一想法就是暴力求解,仔细算一下复杂度,发现这肯定耗时很久,于是看了很多博客(见转载).我们用回溯搜出来正解.
- C# 一个初学者对 依赖注入 IOC 的理解( 含 Unity 的使用)
通过 人打电话 来谈谈自己对IOC的理解 版本1.0 public class Person { public AndroidPhone Phone { get; set; } public void ...
- vue+mint-ui的微博页面(支持评论@添加表情等)
github地址 https://github.com/KyrieZbw/Sneakers (如果觉得不错就给个小星星) 预览地址 页面展示 技术栈 vue2 + vuex + vue-router ...