这题乍一看与半平面交并没有什么卵联系,然而每个靶子都可以转化为两个半平面。

scanf("%lf%lf%lf",&x,&ymin,&ymax);

于是乎就有ymin<=ax^2+bx<=ymax。(因为抛物线一定经过点(0,0),所以c=0)

考虑前一个有ax^2+bx>=ymin  <=>  ax^2+bx-ymin>=0。

#define A x^2

#define B x

#define C ymin

#define x' a

#define y' b

于是乎Ax'+By'+c>=0

这个式子貌似在哪见过的样子

于是乎上半平面交。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define pi (acos(-1.0))
#define maxn 200100
#define double long double
const long long inf=1e15;
int n,tot,sum; double sqr(double x){return x*x;} struct point{
double x,y;
}p[maxn]; struct line{
point from,to;
int id;
double slope;
}l[maxn],q[maxn],a[maxn]; point operator -(point a,point b){return(point){a.x-b.x,a.y-b.y};}
point operator +(point a,point b){return(point){a.x+b.x,a.y+b.y};}
double operator *(point a,point b){return a.x*b.y-a.y*b.x;}
bool operator ==(line a,line b){return a.slope==b.slope;}
bool operator <(line a,line b){
return a.slope<b.slope||(a.slope==b.slope && (a.to-a.from)*(b.to-a.from)<);
} point getpoint(line a,line b){
double t1=(b.to-a.from)*(a.to-a.from),t2=(a.to-a.from)*(b.from-a.from);
double t=t1/(t1+t2);
return (point){(b.from.x-b.to.x)*t+b.to.x,(b.from.y-b.to.y)*t+b.to.y};
} bool check(line a,line b,line c){
point d=getpoint(a,b);
return (c.to-c.from)*(d-c.from)<;
} bool bo(int x){
int cnt=;
for (int i=;i<=sum;i++) if (l[i].id<=x) a[++cnt]=l[i];
int head=,tail=;
q[]=a[],q[]=a[];
for (int i=;i<=cnt;i++){
while (head<tail && check(q[tail-],q[tail],a[i])) tail--;
while (head<tail && check(q[head+],q[head],a[i])) head++;
q[++tail]=a[i];
}
while (head<tail && check(q[tail-],q[tail],q[head])) tail--;
while (head<tail && check(q[head+],q[head],q[tail])) head++;
return tail>head+;
} int main(){
scanf("%d",&n);
l[++tot].to=(point){-inf,inf},l[tot].from=(point){inf,inf};
l[++tot].to=(point){inf,inf},l[tot].from=(point){inf,-inf};
l[++tot].to=(point){inf,-inf},l[tot].from=(point){-inf,-inf};
l[++tot].to=(point){-inf,-inf},l[tot].from=(point){-inf,inf};
for (int i=;i<=n;i++){
double x,y1,y2;
scanf("%llf%llf%llf",&x,&y1,&y2);
double A=sqr(x),B=x,C=-y1;
l[++tot].from=(point){-,(A-C)/B},l[tot].to=(point){,(-A-C)/B},l[tot].id=i;
C=-y2;
l[++tot].from=(point){,(-A-C)/B},l[tot].to=(point){-,(A-C)/B},l[tot].id=i;
} for (int i=;i<=tot;i++) l[i].slope=atan2(l[i].to.y-l[i].from.y,l[i].to.x-l[i].from.x);
sort(l+,l+tot+);
sum=unique(l+,l+tot+)-l;
sum--;
int l=,r=n;
while (l<=r){
int mid=(l+r)>>;
if (bo(mid)) l=mid+;
else r=mid-;
}
printf("%d",r);
return ;
}

bzoj2732: [HNOI2012]射箭 半平面交的更多相关文章

  1. bzoj 2732: [HNOI2012]射箭 半平面交

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2732 题解: 这道题的做法我不想说什么了... 其他题解都有说做法... 即使是我上午做 ...

  2. bzoj 2732 射箭 半平面交

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

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

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

  4. [bzoj2732][HNOI2012]射箭

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

  5. 【BZOJ-4515】游戏 李超线段树 + 树链剖分 + 半平面交

    4515: [Sdoi2016]游戏 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 304  Solved: 129[Submit][Status][ ...

  6. poj3335 半平面交

    题意:给出一多边形.判断多边形是否存在一点,使得多边形边界上的所有点都能看见该点. sol:在纸上随手画画就可以找出规律:按逆时针顺序连接所有点.然后找出这些line的半平面交. 题中给出的点已经按顺 ...

  7. POJ3525 半平面交

    题意:求某凸多边形内部离边界最远的点到边界的距离 首先介绍半平面.半平面交的概念: 半平面:对于一条有向直线,它的方向的左手侧就是它所划定的半平面范围.如图所示: 半平面交:多个半平面的交集.有点类似 ...

  8. POJ 3130 How I Mathematician Wonder What You Are! /POJ 3335 Rotating Scoreboard 初涉半平面交

    题意:逆时针给出N个点,求这个多边形是否有核. 思路:半平面交求多边形是否有核.模板题. 定义: 多边形核:多边形的核可以只是一个点,一条直线,但大多数情况下是一个区域(如果是一个区域则必为 ).核内 ...

  9. bzoj2618[Cqoi2006]凸多边形 半平面交

    这是一道半平面交的裸题,第一次写半平面交,就说一说我对半平面交的理解吧. 所谓半平面交,就是求一大堆二元一次不等式的交集,而每个二元一次不等式的解集都可以看成是在一条直线的上方或下方,联系直线的标准方 ...

随机推荐

  1. repeater中后台动态为控件添加属性

    在此贴出repeater中的ItemDataBound事件中的代码: private void ItemDataBound(object sender, RepeaterItemEventArgs e ...

  2. SIP SDP RTSP RTP RTCP webrtc

    rfc1889  rfc2326  rfc3261  rfc3550  rfc3856  rfc6120. SIP SDP RTSP  RTP RTCP,就像他们出现的顺序一样,他们在实际应用中的启用 ...

  3. java 访问权限控制

    java提供四种访问权限: public > protected > 包访问权限(无关键词) > private 包:库单元 对于包访问权限,一个包内的都可以访问. 在eclipse ...

  4. grub名词理解

    http://baike.baidu.com/link?url=HDv2WL37x1EBS51pCHqbGQIFx7aAJ91h-0afrjOy1UH6MjhKUFPnvjNkOU32OHdVoTS7 ...

  5. html的框架

  6. MSSQLSERVER数据库- 上移和下移的存储过程

    做一下备忘 MOVEUP: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[Proc_MoveUp] @id ...

  7. java19 先开服务器,再开客户端

    先开服务器,再开客户端. import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOExcep ...

  8. Free and Open Source Load-Balancing Software and Projects--转

    http://www.inlab.de/articles/free-and-open-source-load-balancing-software-and-projects.html This ove ...

  9. cglib源码分析(二):Class name 生成策略

    一.如何获取动态生成的class 字节码 结合生成的class文件是一个学习cglib的比较好的方法.在cglib中,生成的class文件默认只存储在内存中,我们可以在代码中加入下面语句来获取clas ...

  10. bit,byte,char,string区别与基本类型认识

    bit.byte.位.字节.汉字的关系 1 bit     = 1  二进制数据        1 byte  = 8  bit        1 字母 = 1  byte = 8 bit       ...