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 ...
随机推荐
- Gson使用技巧
1. CharMatcher String serviceUrl = CharMatcher.is('/').trimTrailingFrom(ConfigHelper.metaServiceUrl( ...
- Servlet (三)HttpServletResponse
package cn.sasa.serv; import java.io.IOException; import javax.servlet.ServletException; import java ...
- MySQL准入规范及容量评估
一.数据库设计 1.表结构设计 -表中的自增列(auto_increment属性)推荐使用bigint类型 -首选使用非空的唯一键, 其次选择自增列或发号器 不使用更新频繁的列,尽量不选择字符串列,不 ...
- open():打开文件
1.open():使用指定的模式和编码打开文件,返回文件读写对象 2.使用说明: (1)使用格式:open(filename [, mode [, bufsize]])(2)打开一个文件,返回一个fi ...
- Python创建目录
需要包含os模块进来,使用相关函数即可实现目录的创建 1.创建目录要用到的函数: (1)os.path.exists(path) 判断一个目录是否存在 (2)os.makedirs(path) 多层创 ...
- shell脚本中 if 判断时候-s是什么意思
-s file 文件大小非0时为真[ -f "somefile" ] :判断是否是一个文件 [ -x "/bin/ls" ] :判断/bin/ls是否存在并有可 ...
- Centos7 下 yum -y install ntp 出现/var/run/yum.pid 已被锁定
[root@localhost ~ ]# yum -y install ntp已加载插件:fastestmirror, langpacksRepodata is over 2 weeks old. I ...
- C 语言循环结构
25.有如下程序 main() { int i,sum; for(i=1;i<=3;sum++) sum+=i; printf("%d\n",sum); } 该程序的执行 ...
- 开发中清除css加载的缓存使用
- linux上pem格式私钥转pfx格式证书的命令
1.root.csr 可改成其它名字,后缀名不改 openssl req -new -key 私钥名称.pem -out root.csr 2.root.crt 可改成其它名字,后缀名不改 opens ...