LA 4253 Archery 二分
题意:
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 二分的更多相关文章
- LA 4253 箭术(二分枚举)
https://vjudge.net/problem/UVALive-4253 题意: 有n个平行于x轴的线段,每条线段代表一个靶子.判断是否可以站在x轴上[0,W]区间内的某个位置射箭. 思路:二分 ...
- UVa LA 4254 - Processor 二分,贪心 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- Netty中CompositeByteBuf的理解以及读写操作
转载请注明出处 https://www.cnblogs.com/majianming/articles/the_composite_byte_buf_read_and_wite_operation_o ...
- LA 2678 Subsequence(二分查找)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- LA 4725 (二分) Airport
题意: 有W.E两个跑道,在每个时刻每个跑道的飞机都从0开始编号,而且每个时刻都有Wi和Ei架飞机到达这两个跑道.而且每个时刻只能选择一个跑道的一架飞机起飞.问如何选择才能使得飞机的最大编号最小.(每 ...
- LA 3971 (二分) Assemble
题意: 你有b块钱想要组装一台电脑.给出n个配件的种类,品质和价格,要求每个种类的配件各买一个总价格不超过b且“品质最差配件”的品质因子应尽量大. 这种情况下STL的map的确很好用,学习学习 这种最 ...
- Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- LA 3268 号码簿分组(最大流+二分)
https://vjudge.net/problem/UVALive-3268 题意: 有n个人和m个组.一个人可能属于很多组.现在请你从某些组中去掉几个人,使得每个人只属于一个组,并使得人数最多的组 ...
随机推荐
- Spring Bean的一生
Spring Bean的一生 When you work directly in Java, you can do anything you like with your objects and do ...
- css实现瀑布流
<style> .container{ column-width:250px; -webkit-column-width:250px; ...
- 洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here
你的飞碟在这儿 难度:☆ Code: #include<iostream> #include<cstring> #include<cstdio> using nam ...
- cf1027F. Session in BSU(并查集 匈牙利)
题意 题目链接 $n$个人,每个人可以在第$a_i$天或第$b_i$,一天最多考一场试,问在最优的情况下,最晚什么时候结束 Sol 自己只能想到暴力匈牙利二分图匹配,然而还是被构造数据卡了.. 标算很 ...
- Vue Scroller:Vue 下拉刷新及无限加载组件
Vue Scroller Vue Scroller is a foundational component ofVonic UI. In purpose of smooth scrolling, pu ...
- Kendo MVVM 数据绑定(十一) Value
Kendo MVVM 数据绑定(十一) Value Value 绑定可以把 ViewModel 的某个属性绑定到 DOM 元素或某个 UI 组件的 Value 属性.当用户修改 DOM 元素或 UI ...
- bt5r3开启远程登录
sshd-generate /etc/init.d/ssh restart
- Java 反射机制(一)
阅读<Core Java Volume I --- Fundamentals>反射部分,总觉得许多概念艰涩难懂.模棱两可.我想造成这个结果的主要原因可能是Cay S. Horstmann和 ...
- pycharm使用秘籍 和 pip命令
python使用requirements.txt批量安装包 requirements.txt文件格式: requests==1.2.0 Flask==0.10.1 等等一系列包 cd 到requir ...
- 洛谷 P2380 狗哥采矿
题目背景 又是一节平静的语文课 狗哥闲来无事,出来了这么一道题 题目描述 一个n*m的矩阵中,每个格子内有两种矿yeyenum和bloggium,并且知道它们在每个格子内的数量是多少.最北边有blog ...