BZOJ 2732 射箭
http://www.lydsy.com/JudgeOnline/problem.php?id=2732
题意:给你n个靶子,让你求是否有一个经过原点的抛物线经过最多的前k个靶子,求出最大的k
思路:
就是这样的形式:y1<=ax^2+bx<=y2,这里y1,y2,x是已知的,有多组,我们发现,变量只有a和b了,而且都是一次,这样就转换成二元一次不等式组,这个问题就是高二学过的线性规划了
可以把它转换成半平面交,然后二分答案就可以了。
坑点:TM BZOJ上面要用longdouble,不然会WA一发,还有,考试的时候我居然在二分里面排序,导致复杂度退化到nlog^2 n T_T,这点要记住了。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define dou long double
const dou inf=1e15;
int tot,n;
struct Point{
dou x,y;
Point(){}
Point(dou x0,dou y0):x(x0),y(y0){}
};
struct Line{
Point s,e;
dou slop;
int id;
Line(){}
Line(Point s0,Point e0):s(s0),e(e0){}
}l[],c[],L[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-')f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
dou operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
bool cmp(Line p1,Line p2){
if (p1.slop==p2.slop) return (p2.e-p1.s)*(p1.e-p1.s)>=;
else return p1.slop<p2.slop;
}
Point inter(Line p1,Line p2){
dou k1=(p2.e-p1.s)*(p1.e-p1.s);
dou k2=(p1.e-p1.s)*(p2.s-p1.s);
dou t=(k2)/(k1+k2);
dou x=p2.s.x+(p2.e.x-p2.s.x)*t;
dou y=p2.s.y+(p2.e.y-p2.s.y)*t;
return Point(x,y);
}
bool jud(Line p1,Line p2,Line p3){
Point p=inter(p1,p2);
return (p-p3.s)*(p3.e-p3.s)>;
}
bool check(int mid){
int Tot=;
for (int i=;i<=tot;i++)
if (l[i].id<=mid) L[++Tot]=l[i];
int cnt=;
for (int i=;i<=Tot;i++)
if (L[i].slop!=L[i-].slop) L[++cnt]=L[i];
int ll=,rr=;
c[]=L[];c[]=L[];
for (int i=;i<=Tot;i++){
while (ll<rr&&jud(c[rr],c[rr-],L[i])) rr--;
while (ll<rr&&jud(c[ll],c[ll+],L[i])) ll++;
c[++rr]=L[i];
}
while (ll<rr&&jud(c[rr],c[rr-],c[ll])) rr--;
while (ll<rr&&jud(c[ll],c[ll+],c[rr])) ll++;
if (rr-ll+<) return ;
else return ;
}
int main(){
n=read();
l[++tot].s=Point(-inf,inf);l[tot].e=Point(-inf,-inf);
l[++tot].s=Point(-inf,-inf);l[tot].e=Point(inf,-inf);
l[++tot].s=Point(inf,-inf);l[tot].e=Point(inf,inf);
l[++tot].s=Point(inf,inf);l[tot].e=Point(-inf,inf);
for (int i=;i<=n;i++){
dou x=read(),y1=read(),y2=read();
l[++tot].s.x=-;l[tot].s.y=y1/x-(-)*x;
l[tot].e.x=;l[tot].e.y=y1/x-x;
l[tot].id=i;
l[++tot].s.x=;l[tot].s.y=y2/x-x;
l[tot].e.x=-;l[tot].e.y=y2/x+x;
l[tot].id=i;
}
for (int i=;i<=tot;i++) l[i].slop=atan2(l[i].e.y-l[i].s.y,l[i].e.x-l[i].s.x);
std::sort(l+,l++tot,cmp);
int LL=,RR=n,ans=;
while (LL<=RR){
int mid=(LL+RR)>>;
if (check(mid)) ans=mid,LL=mid+;
else RR=mid-;
}
printf("%d",ans);
}
BZOJ 2732 射箭的更多相关文章
- bzoj 2732 射箭 半平面交
2732: [HNOI2012]射箭 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2531 Solved: 848[Submit][Status] ...
- BZOJ 2732: [HNOI2012]射箭
2732: [HNOI2012]射箭 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2532 Solved: 849[Submit][Status] ...
- bzoj 2732: [HNOI2012]射箭 半平面交
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2732 题解: 这道题的做法我不想说什么了... 其他题解都有说做法... 即使是我上午做 ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
- 2732: [HNOI2012]射箭( 半平面交 )
很久没写题解了= =,来水一发吧= = 首先这道题很明显就是求y=ax^2+bx的是否有值取,每一个式子都代表着两个半平面,然后直接半平面交就行了 借鉴了hzwer的代码,还是特别简洁的说 CODE: ...
- [HNOI2012]射箭
Description 沫沫最近在玩一个二维的射箭游戏,如下图 1 所示,这个游戏中的 x 轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴.沫沫控制一个位于( ...
- [HNOI2012][BZOJ2732] 射箭 [二分+半平面交]
题面 BZOJ题面 思路 半平面交代码讲解戳这里,用的就是这道题 我们射箭的函数形如$y=Ax^2+Bx$ 考虑每一个靶子$(x_0,y_1,y_2)$,实际上是关于$A,B$的不等式限制条件 我们只 ...
- BZOJ2732:[HNOI2012]射箭——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2732 https://www.luogu.org/problemnew/show/P3222#su ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- 【转】Android:ListView常见错位之CheckBox错位
原文网址:http://blog.csdn.net/lemon_tree12138/article/details/39337867 ListView在什么样的情况下会出现错位?错位的原因是什么?怎么 ...
- php PDO操作乱码问题
前阶段用php写了一个小网页(每周一练),然后就一直忙着其他事也没管它,今天想着给它写个添加数据的页面,用pdo操作,没想到插入数据库的中文数据竟然乱码了,竟然乱码了!然后我就方了,赶紧检测数据传输过 ...
- ubuntu下安装pdo扩展
ubuntu下安装好LAMP后默认情况没有安装mysql_pdo扩展,以下是安装 步聚,在终端输入以下命令 1.pecl search pdo 2.sudo pecl install pdo 当出现E ...
- CentOS 设置mysql的远程访问
好记性不如烂笔头,记录一下. 安装了MySQL默认是拒绝远程连接的. 首先进入数据库,使用系统数据库mysql. mysql -u root -p mysql #回车,然后输入则使用了系统数据库 接着 ...
- [教程] 神器i9100刷基带与内核的方法!(兼带ROOT方法)
http://bbs.hiapk.com/thread-2647905-1-1.html ------何为基带?何为内核? 为什么刷基带,为什么刷内核?!!! 基带:基带(Baseband)是手机中的 ...
- (ubuntu)在andorid andk工程中使用ccache加速编译速度
环境 系统:Linux luogw-pc 3.5.0-36-generic #57~precise1-Ubuntu SMP Thu Jun 20 18:21:09 UTC 2013 x86_64 x8 ...
- android 删除的警告对话框
在图形界面之中,对话框也是人机交互的一种重要的形式,程序可以通过对话框对用户进行一些信息的提示,而 用户也可以通过对话框和程序进行一些简单的交互操作. 在Android的开发之中,所有的对话框都是从a ...
- [Angular 2] Refactoring mutations to enforce immutable data in Angular 2
When a Todo property updates, you still must create a new Array of Todos and assign a new reference. ...
- SQL数值函数
/*abs(n)返回参数n所指定数值的绝对值(如果参数值为NULL,则返回结果为NULL,下同).*/--SELECT ABS(-3.14) FROM DUAL; --3.14 /*round(n[, ...
- rpm包安装
RPM全称是“RedHatPackageManager”是由RedHat公司发发展起来的,本质是将软件源码包经过编译并且打包成rpm的格式,rpm文件包含的有二进制文件,配置文件,库文件等,同时RPM ...