每日一题 day35 打卡

Analysis

先将不符合条件的区间去掉(即半径小于W,不然宽度无法符合),将符合条件的按区间存入节点中。区间的左边界是x-sqrt(r*r-W*W/4.0),要计算x轴的最小长度,而不是x-r。然后将区间按照左边界从小到大排序,依次找到能够覆盖L点的最大右端点。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define int long long
#define maxn 15000+10
#define rep(i,s,e) for(register int i=s;i<=e;++i)
using namespace std;
inline int read()
{
int x=;
bool f=;
char c=getchar();
for(; !isdigit(c); c=getchar()) if(c=='-') f=;
for(; isdigit(c); c=getchar()) x=(x<<)+(x<<)+c-'';
if(f) return x;
return -x;
}
inline void write(int x)
{
if(x<){putchar('-');x=-x;}
if(x>)write(x/);
putchar(x%+'');
}
int T,n,L,W,num,ans;
struct node
{
double x,y;
}reg[maxn];
bool cmp(node x,node y)
{
return x.x<y.x;
}
signed main()
{
T=read();
while(T--)
{
num=;
memset(reg,,sizeof(reg));
n=read();L=read();W=read();
rep(i,,n)
{
int x=read(),r=read();
if(r<=W/) continue;
reg[++num].x=x-sqrt((double)r*r-(double)W*W/4.0);
reg[num].y=x+sqrt((double)r*r-(double)W*W/4.0);
}
sort(reg+,reg+num+,cmp);
int cnt=,ans=;
double now=;
while(now<L)
{
++ans;
double re=now;
while(reg[cnt].x<=re&&cnt<=num)
{
if(now<reg[cnt].y) now=reg[cnt].y;
++cnt;
}
if(re==now&&now<L)
{
ans=-;
break;
}
}
write(ans);
putchar('\n');
}
return ;
}

请各位大佬斧正(反正我不认识斧正是什么意思)

LOJ P10002 喷水装置 题解的更多相关文章

  1. LOJ 一本通一句话题解系列:

    第一部分 基础算法 第 1 章 贪心算法 1):「一本通 1.1 例 1」活动安排:按照结束时间排序,然后扫一遍就可以了. 2):「一本通 1.1 例 2」种树:首先要尽量的往区间重叠的部分种树,先按 ...

  2. LOJ 10002 喷水装置 未完

    #include<bits/stdc++.h> using namespace std; int T,n,l,w; ; struct S{ double s,t; }a[maxn]; bo ...

  3. LOJ P10249 weight 题解

    每日一题 day58 打卡 Analysis 这道题搜索的想法非常巧妙,从两端向中间找,这样可以保证仅仅对于head或tail而言,需要用到的前缀和与后缀和是单调递增的,这样排个序就解决了. 值得一提 ...

  4. LOJ P10013 曲线 题解

    每日一题 day38 打卡 Analysis 这道题运用的是三分,就是说具有一定的单调性,找最大最小值,然后和二分基本类似,就是说特性就是说当前两个点比较,较优的点和最优点在相对了较差点的同侧,就是说 ...

  5. LOJ P10016 灯泡 题解

    每日一题 day50 打卡 Analysis 用初中学的相似推一波式子,再用三分一搞就好了. #include<iostream> #include<cstdio> #incl ...

  6. LOJ P10015 扩散 题解

    每日一题 day49 打卡 Analysis 用dis数组记录每两个点之间的时间,再用一个传递闭包来维护最小的时间就好了 #include<iostream> #include<cs ...

  7. LOJ 10214 计算器 题解

    题面 k==1时,快速幂就好了: k==2时,exgcd就好了,但要注意取模范围的控制: k==3时,BSGS可以解决高次同余方程: 然后就可以开心的A掉了,但要注意特殊情况的特判 #include ...

  8. LOJ #10002. 喷水装置

    题目 裸的贪心. 基本思想见图: Code: #include<iostream> #include<cstdio> #include<cstring> #incl ...

  9. csp-s 考前刷题记录

    洛谷 P2615 神奇的幻方 洛谷 P2678 跳石头 洛谷 P1226 [模板]快速幂||取余运算 洛谷 P2661 信息传递 LOJ P10147 石子合并 LOJ P10148 能量项链 LOJ ...

随机推荐

  1. linux 挂载新的硬盘

    linux 挂载新的硬盘 1.查看硬盘情况,物理盘和分区 fdisk -l 2.分区一个盘,sdb是个还没有分区的硬盘 fdisk /dev/sdb 输入 n p 1 w n 表示新建分区 p 表示分 ...

  2. 【LEETCODE】63、数组分类,hard级别,题目:85、4、84

    package y2019.Algorithm.array.hard; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.arr ...

  3. S02_CH12_ AXI_Lite 总线详解

    S02_CH12_ AXI_Lite 总线详解 12.1前言 ZYNQ拥有ARM+FPGA这个神奇的架构,那么ARM和FPGA究竟是如何进行通信的呢?本章通过剖析AXI总线源码,来一探其中的秘密. 1 ...

  4. Jenkins版本迭代以及回滚

    一.摘要 在上一篇文章,链接如下: https://www.cnblogs.com/xiao987334176/p/11434849.html 镜像打的是latest版,如果需要回滚的话,就比较麻烦了 ...

  5. Golang资料集

    <Platform-native GUI library for Go> 介绍:跨平台的golang GUI库,支持Windows(xp以上),Unix,Mac OS X(Mac OS X ...

  6. .net Dapper 实践系列(2) ---事务添加(Layui+Ajax+Dapper+MySQL)

    目录 写在前面 问题描述 解决方法 具体实现 写在前面 前面我们已经搭建好了项目,这一小节我们使用Dapper 中的事务实现一对多的添加操作. 问题描述 在做添加的时候很头疼需要从页面传递一组数据到后 ...

  7. 资料汇总_Gitlab使用记录

    1)搭建并配置本地GitLab服务器教程 https://www.cnblogs.com/yinkemeng/p/10144782.html 2)记一次为gitlab启用CI的过程 https://w ...

  8. docker部署Asp.Net Core、Nginx、MySQL

    2019/10/24,docker19.03.4, .netcore 3.0,CentOS7.6 摘要:asp.net core 3.0 网站项目容器化部署,使用docker-compose编排Ngi ...

  9. MVC学习笔记(一)—用EF创建数据库

    1.新建MVC项目     2.在Models文件夹下添加名为User的新类   2.1 Users类中的代码为: public class Users { /// <summary> / ...

  10. Python报错:ImportError: cannot import name 'ConnectionRefusedError'

    启动了一个flask server,结果报了标题中的错误. ImportError: cannot import name 'ConnectionRefusedError' 解决: pip insta ...