[Codeforces Round472C] Three-level Laser
[题目链接]
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的更多相关文章
- Codeforces 847I - Noise Level
847I - Noise Level 思路:bfs. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- codeforces 957 C Three-level Laser
题意: 说的是一个电子云的三种状态,但是这不重要. 简单来说,就是在一个升序的序列中找三个数x,y,z,x和z的值之差不超过u,然后使得(z – y) / (z – x)最大. 思路: 使得(z – ...
- CodeForces 731D 80-th Level Archeology
区间并. 对于上下两个数字,如果不一样,那么可以计算出哪一段范围内可以保证字典序,并且后面所有位置都无需再考虑.对所有范围求交集就是答案了. 求交集写起来有点烦,直接对不可取的范围求并即可. #pra ...
- [Linux] pwm设备驱动调试
转载请注明出处:https://www.cnblogs.com/lialong1st/p/11436190.html CPU:RK3288 系统:Linux 客户需求是通过 pwm 控制激光的强弱,写 ...
- 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 ...
- 【codeforces 731D】80-th Level Archeology
[题目链接]:http://codeforces.com/contest/731/problem/D [题意] 给你n个象形文; 每个象形文由l[i]个数字组成; 你可以把所有的组成象形文的数字同时增 ...
- Codeforces 15B Laser
题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- [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 ...
- Codeforces Round #689 (Div. 2, based on Zed Code Competition) E. Water Level (贪心好题)
题意:你在一家公司工作\(t\)天,负责给饮水机灌水,饮水机最初有\(k\)升水,水的范围必须要在\([l,r]\)内,同事每天白天都会喝\(x\)升水,你在每天大清早可以给饮水机灌\(y\)升水,问 ...
随机推荐
- ThinkPHP---thinkphp模型(M)
(1)配置数据库连接 数据库的连接配置可以在系统配置文件ThinkPHP/Conf/convention.php中找到 /* 数据库设置 */ 'DB_TYPE' => '', // 数据库类型 ...
- 04Microsoft SQL Server 数据库创建,查看,使用,修改及删除
Microsoft SQL Server 数据库创建,查看,使用,修改及删除 创建数据库 创建普通数据库 USE [master] GO CREATE DATABASE [MyDataBase] -- ...
- MongoDB 启动和关闭
重启命令 service mongodb restart 启动命令 mongod -f /data/tools/mongodb/config/config.conf 必须要带配置文件才能启动 关闭命令 ...
- jQuery图片延迟加载插件jQuery.lazyload 的使用
使用方法 引用jquery和jquery.lazyload.js到你的页面 1 2 <script src="jquery-1.11.0.min.js"></sc ...
- Vijos P1334 NASA的食物计划
解法 二维费用01背包问题 解法就是先枚举物品再枚举条件这里两个条件所以要枚举两个for 代码 #include <bits/stdc++.h> using namespace std; ...
- Ubuntu16.04安装rabbitmq(实战)
安装Erlang 由于RabbitMQ需要基于Erlang/OTP,所以在安装RabbitMQ之前需要先安装Erlang/OTP.同样的,在Ubuntu标准的repositories中,Erlang/ ...
- 爬虫-----HTML解析
对HTML的解析: 在解析复杂的HTML的页面时,需要避免一些问题,好让爬虫工作变得得心应手. • 寻找“打印此页”的链接,或者看看网站有没有HTML样式更友好的移动版(把自己 的请求头设置成处于移动 ...
- Spring 获取当前activeProfile
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext()) ...
- noip模拟赛 立方数
题目描述LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8,27就是最小的3个立方数.现在给定一个数P,LYK想要知道这个数是不是立方数.当然你有可 ...
- [USACO 4.2] 完美的牛栏
★★☆ 输入文件:stall4.in 输出文件:stall4.out 简单对比 时间限制:1 s 内存限制:128 MB USACO/stall4(译by Felicia Crazy) ...