• 设抛物线方程\(y = ax^2 + bx\), 那么对于一个靶子\((x_i,y_{down},y_{up})\)我们需要满足的条件就是
  • \(\frac{y_{down}}{x_i} \leq ax_i + b \leq \frac{y_{up}}{x_i}\), 实际上可以看做二维平面上的一个半平面,
  • 然后我们二分能打到的最远距离, 我们只需要求出这些半平面是否有交就好了
  • 当然我们要把ab的合法范围勾选出来, 满足, a < 0, b > 0
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<iostream>
#define ll long long
#define double long double
#define M 600010
#define mmp make_pair
const double inf = pow(2, 60), eps = 1e-12;
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
struct Vec {
double x, y;
Vec () {}
Vec(double a, double b) {
x = a, y = b;
}
Vec operator + (Vec b) {
return Vec(x + b.x, y + b.y);
}
Vec operator - (Vec b) {
return Vec(x - b.x, y - b.y);
}
Vec operator *(double a) {
return Vec(x * a, y * a);
}
double operator ^ (Vec a) {
return x * a.y - y * a.x;
}
} k[M]; struct Line {
Vec p, v;
double k;
int id;
Line() {}
Line(Vec a, Vec b, int c) {
p = a, v = b - a, k = atan2(v.y, v.x), id = c;
}
bool operator < (const Line &b) const
{
return this->k < b.k;
}
bool right(Vec a) {
return (v ^ (a - p)) < -eps;
}
friend Vec cross(Line a, Line b) {
return a.p + a.v * ((b.v ^ (b.p - a.p)) / (b.v ^ a.v));
}
} a[M], q[M];
int tp = 0, n; bool check(int mid) {
int h = 0, t = 0, i = 1;
while(a[i].id > mid) i++;
for(q[0] = a[i++]; i <= tp; i++)
{
if(a[i].id > mid) continue;
while(h < t && a[i].right(k[t - 1])) --t;
while(h < t && a[i].right(k[h]))h++;
if(a[i].k != q[t].k) q[++t] = a[i];
else if(a[i].right(q[t].p)) q[t] = a[i];
if(h < t) k[t - 1] = cross(q[t - 1], q[t]);
}
while(h < t && q[h].right(k[t - 1])) --t;
return t - h > 1;
} int main() {
n = read();
for(int i = 1; i <= n; i++) {
double x = read(), yd = read(), yp = read();
a[++tp] = Line(Vec(0, yd / x), Vec(1, yd / x - x), i);
a[++tp] = Line(Vec(1, yp / x - x), Vec(0, yp / x), i);
}
a[++tp] = Line(Vec(-inf, eps), Vec(-eps, eps), 0);
a[++tp] = Line(Vec(-eps, eps), Vec(-eps, inf), 0);
a[++tp] = Line(Vec(-eps, inf), Vec(-inf, inf), 0);
a[++tp] = Line(Vec(-inf, inf), Vec(-inf, eps), 0);
sort(a + 1, a + tp + 1);
int l = 1, r = n;
while(l + 1 < r) {
int mid = (l + r) >> 1;
if(check(mid)) l = mid;
else r = mid;
}
printf("%d\n", check(r) ? r : l);
return 0;
}

[HNOI2012]射箭(计算几何)的更多相关文章

  1. BZOJ 2732: [HNOI2012]射箭

    2732: [HNOI2012]射箭 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2532  Solved: 849[Submit][Status] ...

  2. 洛谷P3222 [HNOI2012]射箭(计算几何,半平面交,双端队列)

    洛谷题目传送门 设抛物线方程为\(y=ax^2+bx(a<0,b>0)\),我们想要求出一组\(a,b\)使得它尽可能满足更多的要求.这个显然可以二分答案. 如何check当前的\(mid ...

  3. [bzoj2732][HNOI2012]射箭

    Description 沫沫最近在玩一个二维的射箭游戏,如下图所示,这个游戏中的$x$轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴.沫沫控制一个位于$(0, ...

  4. [HNOI2012]射箭

    Description 沫沫最近在玩一个二维的射箭游戏,如下图 1 所示,这个游戏中的 x 轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴.沫沫控制一个位于( ...

  5. BZOJ2732:[HNOI2012]射箭——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=2732 https://www.luogu.org/problemnew/show/P3222#su ...

  6. bzoj2732: [HNOI2012]射箭 半平面交

    这题乍一看与半平面交并没有什么卵联系,然而每个靶子都可以转化为两个半平面. scanf("%lf%lf%lf",&x,&ymin,&ymax); 于是乎就有 ...

  7. 2732: [HNOI2012]射箭( 半平面交 )

    很久没写题解了= =,来水一发吧= = 首先这道题很明显就是求y=ax^2+bx的是否有值取,每一个式子都代表着两个半平面,然后直接半平面交就行了 借鉴了hzwer的代码,还是特别简洁的说 CODE: ...

  8. Luogu-3222 [HNOI2012]射箭

    几何题,二次函数,化一下式子吧 设二次函数\(y=ax^2+bx\),对于一个线段\((x,y1)\),\((x,y2)\),与他相交的条件是\(y1<=ax^2+bx<=y2\) 对于\ ...

  9. 【bzoj2732】[HNOI2012]射箭 二分+半平面交

    题目描述 给出二维平面上n个与y轴平行的线段,求最大的k,使得存在一条形如$y=ax^2+bx(a<0,b>0)$的抛物线与前k条线段均有公共点 输入 输入文件第一行是一个正整数N,表示一 ...

随机推荐

  1. 错误:Bean property 'sessionFactory' is not writable or has an invalid setter method.

    Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' ...

  2. Django学习教程

    教程link:https://code.ziqiangxuetang.com/django/django-install.html 最好用虚拟环境学习django,用pycharm时要注意所选的pyt ...

  3. linux c++ curl https 请求并双向验证SSL证书

    1.配置curl https请求需要提供 CA证书.客户端证书和客户端秘钥,这三个文件的pem格式. 分别对应 curl_easy_setopt() 函数的 下面三个参数: CURLOPT_CAINF ...

  4. 网络知识梳理--OSI七层网络与TCP/IP五层网络架构及二层/三层网络(转)

     reference:https://www.cnblogs.com/kevingrace/p/5909719.html https://www.cnblogs.com/awkflf11/p/9190 ...

  5. 一轮冲刺(NABCD)和需求分析

    N我们的创意是为了解决我们测量人员在测量结束后要计算一些数据的问题,当我们观测角度后,有大量的角度需要计算,有时会用到角度与弧度的转换. A我们测量人员知道计算的公式,了解一些c++和c# B我们这个 ...

  6. git全局忽略文件

    mac系统如何显示和隐藏文件 创建 ~/.gitignore_global .DS_Store __pycache__/ 配置选项 git config --global core.excludesf ...

  7. python 使用gevent模块实现手动挡切换多协程。

    from greenlet import greenlet def test1(): print(12) g2.switch()#切换到协程g2执行,保存执行状态 print(23) g2.switc ...

  8. 成功的拆开了SELECT里JOIN个SELECT是啥

    SELECT * FROM table JOIN table ON a=b ----------------------- JOIN (SELECT* FROM table JOIN table ON ...

  9. linux下查询java进程以及杀掉其进程

    1.使用命令: ps -ef|grep java 查询到到自己想要kill掉的进程id 2.使用命令: kill -9 id(这里的id为你上一步查找到的id)

  10. 【SpringBoot】SpringBoot2.0响应式编程

    ========================15.高级篇幅之SpringBoot2.0响应式编程 ================================ 1.SprinBoot2.x响应 ...