[题目链接]

https://codeforces.com/contest/957/problem/C

[算法]

二分

注意精度问题

时间复杂度 :O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-;
const int MAXN = 1e5 + ; int n,m;
int a[MAXN];
double ans;
bool ok; template <typename T> inline void read(T &x)
{
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x)
{
if (x < )
{
putchar('-');
x = -x;
}
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x)
{
write(x);
puts("");
} int main()
{ read(n); read(m);
for (int i = ; i <= n; i++) read(a[i]);
ans = 0.0; ok = false;
for (int i = ; i <= n; i++)
{
int l = i + , r = n , pos = -;
while (l <= r)
{
int mid = (l + r) >> ;
if (a[mid] - a[i] <= m)
{
pos = mid;
l = mid + ;
} else r = mid - ;
}
if (pos == - || pos == i + ) continue;
if ((1.0 * (a[pos] - a[i + ]) / (a[pos] - a[i]) - ans) > eps)
ans = 1.0 * (a[pos] - a[i + ]) / (a[pos] - a[i]);
ok = true;
}
if (!ok) printf("-1\n");
else printf("%.10lf\n",ans); return ; }

[Codeforces Round472C] Three-level Laser的更多相关文章

  1. Codeforces 847I - Noise Level

    847I - Noise Level 思路:bfs. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  2. codeforces 957 C Three-level Laser

    题意: 说的是一个电子云的三种状态,但是这不重要. 简单来说,就是在一个升序的序列中找三个数x,y,z,x和z的值之差不超过u,然后使得(z – y) / (z – x)最大. 思路: 使得(z – ...

  3. CodeForces 731D 80-th Level Archeology

    区间并. 对于上下两个数字,如果不一样,那么可以计算出哪一段范围内可以保证字典序,并且后面所有位置都无需再考虑.对所有范围求交集就是答案了. 求交集写起来有点烦,直接对不可取的范围求并即可. #pra ...

  4. [Linux] pwm设备驱动调试

    转载请注明出处:https://www.cnblogs.com/lialong1st/p/11436190.html CPU:RK3288 系统:Linux 客户需求是通过 pwm 控制激光的强弱,写 ...

  5. Codeforces Round #376 (Div. 2) D. 80-th Level Archeology —— 差分法 + 线段扫描法

    题目链接:http://codeforces.com/contest/731/problem/D D. 80-th Level Archeology time limit per test 2 sec ...

  6. 【codeforces 731D】80-th Level Archeology

    [题目链接]:http://codeforces.com/contest/731/problem/D [题意] 给你n个象形文; 每个象形文由l[i]个数字组成; 你可以把所有的组成象形文的数字同时增 ...

  7. Codeforces 15B Laser

    题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...

  8. [Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]

    题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n ...

  9. Codeforces Round #689 (Div. 2, based on Zed Code Competition) E. Water Level (贪心好题)

    题意:你在一家公司工作\(t\)天,负责给饮水机灌水,饮水机最初有\(k\)升水,水的范围必须要在\([l,r]\)内,同事每天白天都会喝\(x\)升水,你在每天大清早可以给饮水机灌\(y\)升水,问 ...

随机推荐

  1. CAD指定区域绘制一个jpg文件

    主要用到函数说明: _DMxDrawX::DrawToJpg 把指定区域的内容绘制一个jpg文件中.详细说明如下: 参数 说明 BSTR sJpgFilePath Jpg文件名 DOUBLE dLbx ...

  2. 梦想CAD控件安卓选择集

    在本示例中将使用构造选择集对被过滤对象进行过滤,该类封装了选择集及其处理函数,支持如下过滤条件. 参数类型 类型 RTDXF0 TEXT 文字 MTEXT 多行文字 CIRCLE 圆 ARC 圆弧 L ...

  3. Mybatis逆向工程使用方法

    使用官方网站的mapper自动生成工具mybatis-generator-core-1.3.2来生成po类和mapper映射文件. 一.mapper生成配置文件 在generatorConfig.xm ...

  4. 00JavaScript

    JavaScript JavaScript是由网景公司开发的一种跨平台面向对象(object-oriented)的网页脚本语言(Web Script Language)是目前流行的网页特效设计语言Ja ...

  5. 用sed写配置IP脚本参数

    #!/bin/bash#配置ip地址参数脚本NET=/etc/sysconfig/network-scripts/ifcfg-ens33if grep -E "BOOTPROTO=dhcp& ...

  6. RC: blkio throttle 测试

    本文将测试一下使用cgroup的blkio组来控制IO吞吐量 : 测试环境CentOS 7.x x64 创建一个继承组 [root@150 rg1]# cd /sys/fs/cgroup/blkio/ ...

  7. MyBatis 的基本要素—核心配置文件

    MyBatis 核心配置文件( mybatis-config.xml),该文件配置了 MyBatis 的一些全局信息,包含数据库连接信息和 MyBatis 运行时所需的各种特性,以及设置和影响 MyB ...

  8. Servlet监听器的使用

    Servlet监听器的使用 制作人:全心全意 在Servlet技术中已经定义了一些事件,并且可以针对这些事件来编写相关的事件监听器,从而对事件做出相应的处理.例如,想要在Web应用程序启动和关闭时来执 ...

  9. Django DTL模板语法中的url反转

    """template_url_demo URL Configuration The `urlpatterns` list routes URLs to views. F ...

  10. 第九节:web爬虫之urllib(五)

    第四个模块 robotparser: 主要是用来识别网站的 robots.txt 文件,然后判断哪些网站可以爬,哪些网站不可以爬的,其实用的比较少.