[HNOI2012]射箭(计算几何)
- 设抛物线方程\(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]射箭(计算几何)的更多相关文章
- BZOJ 2732: [HNOI2012]射箭
2732: [HNOI2012]射箭 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2532 Solved: 849[Submit][Status] ...
- 洛谷P3222 [HNOI2012]射箭(计算几何,半平面交,双端队列)
洛谷题目传送门 设抛物线方程为\(y=ax^2+bx(a<0,b>0)\),我们想要求出一组\(a,b\)使得它尽可能满足更多的要求.这个显然可以二分答案. 如何check当前的\(mid ...
- [bzoj2732][HNOI2012]射箭
Description 沫沫最近在玩一个二维的射箭游戏,如下图所示,这个游戏中的$x$轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴.沫沫控制一个位于$(0, ...
- [HNOI2012]射箭
Description 沫沫最近在玩一个二维的射箭游戏,如下图 1 所示,这个游戏中的 x 轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴.沫沫控制一个位于( ...
- BZOJ2732:[HNOI2012]射箭——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2732 https://www.luogu.org/problemnew/show/P3222#su ...
- bzoj2732: [HNOI2012]射箭 半平面交
这题乍一看与半平面交并没有什么卵联系,然而每个靶子都可以转化为两个半平面. scanf("%lf%lf%lf",&x,&ymin,&ymax); 于是乎就有 ...
- 2732: [HNOI2012]射箭( 半平面交 )
很久没写题解了= =,来水一发吧= = 首先这道题很明显就是求y=ax^2+bx的是否有值取,每一个式子都代表着两个半平面,然后直接半平面交就行了 借鉴了hzwer的代码,还是特别简洁的说 CODE: ...
- Luogu-3222 [HNOI2012]射箭
几何题,二次函数,化一下式子吧 设二次函数\(y=ax^2+bx\),对于一个线段\((x,y1)\),\((x,y2)\),与他相交的条件是\(y1<=ax^2+bx<=y2\) 对于\ ...
- 【bzoj2732】[HNOI2012]射箭 二分+半平面交
题目描述 给出二维平面上n个与y轴平行的线段,求最大的k,使得存在一条形如$y=ax^2+bx(a<0,b>0)$的抛物线与前k条线段均有公共点 输入 输入文件第一行是一个正整数N,表示一 ...
随机推荐
- java通过StringToKenizer获取字符串中的单词根据空格分离-详情版
public class DaXie { public static void main(String[] args) { String strin = "Hello Java World! ...
- CentOS 使用yum命令安装出现错误提示”could not retrieve mirrorlist http://mirrorlist.centos.org
CentOS 使用yum命令安装出现错误提示"could not retrieve mirrorlist http://mirrorlist.centos.org这个错误, 在网上找了好多, ...
- 查看shell 命令 路径
type [root@web01 ~]# type mount mount is /bin/mount which [root@web01 ~]# type ifconfig ifconfig is ...
- java service 安装
sudo ln -s /var/services/video/video-live.jar /etc/init.d/live-service sudo chmod +x /var/services/v ...
- jQuery开发API参考
http://jquery.cuishifeng.cn/show.html (原地址)
- 第二周例行报告psp
此作业要求详见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2127 (1)psp表 本周进度条 累计进度图 本周PSP饼状图
- django 分页出现 UnorderedObjectListWarning 错误
django 分页出现此错误: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unorde ...
- 2018idea如何布置tomcat修改URL后连接不到
以下连接 https://blog.csdn.net/cs825900618/article/details/86261019
- scrapy框架之递归解析和post请求
递归爬取解析多页页面数据 scrapy核心组件工作流程 scrapy的post请求发送 1.递归爬取解析多页页面数据 - 需求:将糗事百科所有页码的作者和段子内容数据进行爬取切持久化存储 - 需求分析 ...
- 《从Lucene到Elasticsearch:全文检索实战》学习笔记一
今天,我主要给大家讲一下信息检索概念. 信息检索: 互联网时代的飞速发展使人们进入了信息爆炸时代,据统计全球的互联网用户已达到30亿,在各个网站及移动app在每个分钟 产生的数据量是巨大的,从而导致数 ...