题意:

x轴上方有若干条平行于x轴的线段

在x轴的区间\([0, \, W]\)内找一点发射一条射线,使其穿过所有线段。

问是否存在这样的点。

分析:

我们二分射线端点的坐标,将线段按纵坐标从小到大排序,维护一个可以穿过所有线段的极角区间。

如果该区间为空说明这个点不符合要求,我们可以根据扫描到的最后一条线段来调整出射点的位置。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std; const int maxn = 5000 + 10; typedef long double LD;
const LD eps = 1e-10; int dcmp(LD x) {
if(fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
} struct Segment
{
LD y, l, r; void read() { cin >> y >> l >> r; } bool operator < (const Segment& a) const {
return y < a.y;
}
}; int n;
LD W;
Segment seg[maxn]; int check(LD x) {
LD L = atan2(seg[0].y, seg[0].r - x);
LD R = atan2(seg[0].y, seg[0].l - x); for(int i = 1; i < n; i++) {
LD l = atan2(seg[i].y, seg[i].r - x);
LD r = atan2(seg[i].y, seg[i].l - x);
if(dcmp(l - R) > 0) return 1;
if(dcmp(r - L) < 0) return -1;
L = max(L, l);
R = min(R, r);
}
return 0;
} int main()
{
//freopen("4253.txt", "r", stdin); int T; scanf("%d", &T);
while(T--) {
cin >> W;
scanf("%d", &n);
for(int i = 0; i < n; i++) seg[i].read();
sort(seg, seg + n); double L = 0, R = W;
bool ok = false;
for(int i = 0; i < 100; i++) {
LD mid = (L + R) / 2;
int t = check(mid);
if(t == 1) L = mid;
else if(t == -1) R = mid;
else {
ok = true;
break;
}
} printf("%s\n", ok ? "YES" : "NO");
} return 0;
}

LA 4253 Archery 二分的更多相关文章

  1. LA 4253 箭术(二分枚举)

    https://vjudge.net/problem/UVALive-4253 题意: 有n个平行于x轴的线段,每条线段代表一个靶子.判断是否可以站在x轴上[0,W]区间内的某个位置射箭. 思路:二分 ...

  2. UVa LA 4254 - Processor 二分,贪心 难度: 1

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  3. Netty中CompositeByteBuf的理解以及读写操作

    转载请注明出处 https://www.cnblogs.com/majianming/articles/the_composite_byte_buf_read_and_wite_operation_o ...

  4. LA 2678 Subsequence(二分查找)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  5. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  6. LA 4725 (二分) Airport

    题意: 有W.E两个跑道,在每个时刻每个跑道的飞机都从0开始编号,而且每个时刻都有Wi和Ei架飞机到达这两个跑道.而且每个时刻只能选择一个跑道的一架飞机起飞.问如何选择才能使得飞机的最大编号最小.(每 ...

  7. LA 3971 (二分) Assemble

    题意: 你有b块钱想要组装一台电脑.给出n个配件的种类,品质和价格,要求每个种类的配件各买一个总价格不超过b且“品质最差配件”的品质因子应尽量大. 这种情况下STL的map的确很好用,学习学习 这种最 ...

  8. Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  9. LA 3268 号码簿分组(最大流+二分)

    https://vjudge.net/problem/UVALive-3268 题意: 有n个人和m个组.一个人可能属于很多组.现在请你从某些组中去掉几个人,使得每个人只属于一个组,并使得人数最多的组 ...

随机推荐

  1. POJA Star not a Tree?(模拟退火)

    题意 题目链接 给出$n$个点,求出一个点使得到各个点的距离之和最小,距离为欧几里得距离 Sol 模拟退火真是玄学,我退了一上午,最后把exp函数去了就A了. 后来改了改,发现是大小符号的问题.. 但 ...

  2. Kendo MVVM 数据绑定(七) Invisible/Visible

    Kendo MVVM 数据绑定(七) Invisible/Visible Invisible/Visible 绑定可以根据 ViewModel 的某个属性来显示/隐藏 DOM 元素.例如: <d ...

  3. Update主循环的实现原理

    从写一段程序,到写一个app,写一个游戏,到底其中有什么不同呢?一段程序的执行时间很短,一个应用的执行时间很长,仅此而已.游戏中存在一个帧的概念. 这个概念大家都知道,类比的话,它就是电影胶卷的格.一 ...

  4. codeforce Gym 100500H ICPC Quest (简单dp)

    题意:给一个nXm的矩阵,上面有一些数字,从左上角出发,每次只能往右或者往下,把沿途的数字加起来,求到达右下角的最大值是多少. 题解:简单的一个dp,设f[i][j]为到达i行j列的最大值,f[i][ ...

  5. 任务管理器 用 Ctrl + Shift + Esc 替换 Ctrl + Alt + Del

    任务管理器 用 Ctrl + Shift + Esc 替换 Ctrl + Alt + Del

  6. stixel-world和psmnet结合出现的问题

    float32位,4字节 原本的stixel-world是用sgbm生成深度图,并且转成了float型 psmnet保存最终的disparity图是保存成uint16的,skimage.io.imsa ...

  7. python 与 json

    +-------------------+---------------+    | Python            | JSON          |    +================= ...

  8. 【转】JavaScript 节点操作 以及DOMDocument属性和方法

    最近发现DOMDocument对象很重要,还有XMLHTTP也很重要 注意大小写一定不能弄错. 属性: 1Attributes 存储节点的属性列表(只读) 2childNodes 存储节点的子节点列表 ...

  9. 自实现RPC调用

    服务提供者 服务接口: public interface HelloService { public String sayHello(String name); } 服务实现类: public cla ...

  10. linux 安装并且设置环境lua环境变量

    在lua官网下载lua安装包并安装: http://www.lua.org/download.html 解压编译: wget http://www.lua.org/ftp/lua-5.3.2.tar. ...