codeforces 957 C Three-level Laser
题意:
说的是一个电子云的三种状态,但是这不重要。
简单来说,就是在一个升序的序列中找三个数x,y,z,x和z的值之差不超过u,然后使得(z – y) / (z – x)最大。
思路:
使得(z – y)/(z – x)最大,那么y与x要尽量接近,并且z – x尽量大,一个比较显然的例子是8/9大于7/8。
对于每一个x,紧邻它的下一个数就是y,然后二分查找最大的小于等于x+u的数字,然后取(z – y) / (z – x)的最大值。
我的失误在于考虑到了最后可能x与z相等,但是没有考虑到y与z也可能相等,这是思维不严谨的地方,mark!
代码:
#include <stdio.h>
#include <string.h>
#include <set>
#include <algorithm>
#include <vector>
using namespace std; vector<int> v; int main()
{
int n,d; scanf("%d%d",&n,&d); double ans = -; for (int i = ;i < n;i++)
{
int x;
scanf("%d",&x);
v.push_back(x);
} for (int i = ;i < n - ;i++)
{
int x = v[i],y = v[i+]; int p = lower_bound(v.begin(),v.end(),x+d) - v.begin(); if (p == n) p--;
while (v[p] > x + d) p--; int z = v[p]; if (x >= z || y >= z) continue; double tmp = 1.0 * (z - y) / (z - x); //printf("%d %d %d\n",x,y,z); ans = max(ans,tmp);
} if (ans < ) printf("-1");
else printf("%.11f",ans); return ;
}
codeforces 957 C Three-level Laser的更多相关文章
- 【codeforces 731D】80-th Level Archeology
[题目链接]:http://codeforces.com/contest/731/problem/D [题意] 给你n个象形文; 每个象形文由l[i]个数字组成; 你可以把所有的组成象形文的数字同时增 ...
- codeforces 957 A. Tritonic Iridescence
题意: 给出一个字符串,要求任意两个相同的字母不能相同,问这个字符串是否能有两种或者两种以上的表现形式. 思路: 简单判断一下: 1.问号在端点: 2.连续两个问号或者以上: 3.一个问号两端的字母是 ...
- Codeforces 957 水位标记思维题
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- [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 Round472C] Three-level Laser
[题目链接] https://codeforces.com/contest/957/problem/C [算法] 二分 注意精度问题 时间复杂度 :O(NlogN) [代码] #include< ...
- Codeforces 847I - Noise Level
847I - Noise Level 思路:bfs. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- 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 ...
随机推荐
- java之旅_高级教程_java泛型
摘自:http://www.runoob.com/java/java-generics.html JAVA泛型 java泛型(generics)是JDK5中引入的新特性,泛型提供了编译时类型安全检测机 ...
- SQL Server 无法连接数据库
1.打开SQL server 配置管理器-->SQL server 网络配置-->实例名的协议 2.保证SQLEXPRESS协议中的Named Pipes和 TCP/IP启用. 3.点击S ...
- es定制排序搜索结果
GET /company/employee/_search { "query": { "constant_score": { "filter" ...
- Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1) Checks autowiring prob
Intellij Idea开发工具在@Autowired或者@Resource注入XxxMapper接口时报如下错误: Could not autowire. No beans of 'TbItemM ...
- 8.1-uC/OS-III多任务应用
1.app.c: ( 1) .分别为每个任务分配一个OS_TCB. (2). 斥信号量( mutex)是一个内核对象(一个结构体),用于保护共享资源.任务要访问共享资源就必须先获得 mutex. mu ...
- docker基本原理
写的很不错的文章,作个存档 什么是容器 容器是 种轻量级.可移植的为应用程序提供了隔离的运行空间 .每个容器内都包含一个独享的完整用户环境,并且 个容器内的环境变动不会影响其他容器的运行环境,可以使应 ...
- Centos7限速和测速
限速 wondershaper是国外人开发的一款在Linux内核下基于TC工具的对整块网卡的限度工具. 第一种安装方法 首先下载wondershaper的rpm安装包:wondershaper-1.1 ...
- (转)Springboot定时任务
在我们的项目开发过程中,经常需要定时任务来帮助我们来做一些内容,springboot默认已经帮我们实行了,只需要添加相应的注解就可以实现 1.pom包配置 pom包里面只需要引入springboot ...
- Python 全栈开发一 python初识
1.Python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ...
- [LeetCode] 849. Maximize Distance to Closest Person_Easy tag: BFS
In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...