题目大意:

http://www.lydsy.com/JudgeOnline/problem.php?id=2732

题解:

这道题的做法我不想说什么了。。。

其他题解都有说做法。。。

即使是我上午做的题,晚上写的题解

看到这道题我就感觉到累.

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 210010; const long double eps = 1e-18;
inline int dcmp(const long double &x){
if(x < eps && x > -eps) return 0;
return x > 0 ? 1 : -1;
}
struct Point{
long double x,y;
Point(){}
Point(const long double &a,const long double &b){
x=a;y=b;
}
};
typedef Point Vector;
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y);
}
Vector operator - (const Vector &a,const Vector &b){
return Vector(a.x-b.x,a.y-b.y);
}
Vector operator * (const Vector &a,const long double &b){
return Vector(a.x*b,a.y*b);
}
long double cross(const Vector &a,const Vector &b){
return a.x*b.y - a.y*b.x;
}
struct line{
Point p;
Vector v;
long double alpha;
int id;
line(){}
line(const Point &a,const Point &b,int i){
p = a;v = b;id = i;
alpha = atan2(v.y,v.x);
// printf("(%lf,%lf) got %lf\n",v.x,v.y,alpha);
}
};
Point lineInterion(const line &l1,const line &l2){
Vector u = l1.p - l2.p;
long double t = cross(l2.v,u)/cross(l1.v,l2.v);
return l1.p + l1.v*t;
}
bool onLeft(const Point &p,const line &l){
return dcmp(cross(l.v,p-l.p)) >= 0;
}
inline bool cmp(const line &a,const line &b){
return a.alpha < b.alpha;
}
line lines[maxn],q[maxn];
Point p[maxn];
int l,r;
inline bool halfInterion(int n){
l = 1;r = 1;q[1] = lines[1];
for(int i=2;i<=n;++i){
while(l < r && !onLeft(p[r-1],lines[i])) -- r;
while(l < r && !onLeft(p[l],lines[i])) ++ l;
if(dcmp(cross(q[r].v,lines[i].v)) == 0)
q[r] = onLeft(q[r].p,lines[i]) ? q[r] : lines[i];
else q[++r] = lines[i];
if(l < r) p[r-1] = lineInterion(q[r],q[r-1]);
}while(l < r && !onLeft(p[r-1],q[l])) -- r;
return (r-l > 1);
}
line a[maxn];
int n,cnt = 0,tot;
inline bool check(int mid){
tot = 0;
for(int i=1;i<=cnt;++i){
if(a[i].id > mid) break;
tot = i;
lines[i] = a[i];
}
sort(lines+1,lines+tot+1,cmp);
return halfInterion(tot);
}
const long double inf = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0;
int main(){
read(n);
double v,L,R;
a[++cnt] = line(Point(-inf,-inf),Point(inf,0),0);
a[++cnt] = line(Point(inf,-inf),Point(0,inf),0);
a[++cnt] = line(Point(inf,inf),Point(-inf,0),0);
a[++cnt] = line(Point(-inf,inf),Point(0,-inf),0);
for(int i=1;i<=n;++i){
scanf("%lf%lf%lf",&v,&L,&R);
L -= eps;R += eps;
a[++cnt] = line(Point(0,R/v),Point(-1/v,1),i);
a[++cnt] = line(Point(0,L/v),Point(1/v,-1),i);
}
int l = 1,r = n,ans = 0;
while(l <= r){
int mid = (l+r) >> 1;
if(check(mid)) ans = mid,l = mid+1;
else r = mid-1;
}printf("%d\n",ans);
getchar();getchar();
return 0;
}

。。。 。。。

下面的那个Ac是粘的hzwer的代码...最上面的才是自己A的

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

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

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

  2. bzoj 2732 射箭 半平面交

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

  3. BZOJ 2732: [HNOI2012]射箭

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

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

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

  5. bzoj 4445 小凸想跑步 - 半平面交

    题目传送门 vjudge的快速通道 bzoj的快速通道 题目大意 问在一个凸多边形内找一个点,连接这个点和所有顶点,使得与0号顶点,1号顶点构成的三角形是最小的概率. 假设点的位置是$(x, y)$, ...

  6. bzoj 3190 赛车 半平面交

    直接写的裸的半平面交,已经有点背不过模板了... 这题卡精度,要用long double ,esp设1e-20... #include<iostream> #include<cstd ...

  7. BZOJ 4445 [Scoi2015]小凸想跑步:半平面交

    传送门 题意 小凸晚上喜欢到操场跑步,今天他跑完两圈之后,他玩起了这样一个游戏. 操场是个凸 $ n $ 边形,$ n $ 个顶点 $ P_i $ 按照逆时针从 $ 0 $ 至 $ n-1 $ 编号. ...

  8. BZOJ 1137: [POI2009]Wsp 岛屿 半平面交

    1137: [POI2009]Wsp 岛屿 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 165  Solved: ...

  9. BZOJ 1829 [Usaco2010 Mar]starc星际争霸 ——半平面交

    发现最终的结果只和$s1$,$s2$,$s3$之间的比例有关. 所以直接令$s3=1$ 然后就变成了两个变量,然后求一次半平面交. 对于每一个询问所属的直线,看看半平面在它的那一侧,或者相交就可以判断 ...

随机推荐

  1. Android 热门技术干货

    http://mp.weixin.qq.com/s?__biz=MzIwMzYwMTk1NA==&mid=2247484939&idx=1&sn=d1871b09de55ca6 ...

  2. DELL inspiron1420 linux下的wifi驱动安装

    首先确定无线网卡类型: lspci -vnn -d 14e4: 比如我的网卡类型为 04:00.0 Network controller [0280]:Broadcom Corporation BCM ...

  3. ArcGIS API for javascript Bookmarks(书签)示例2

    1.运行效果图 说明:这篇博文介绍的书签位于地图之上 有关博文中引用的API文件 怎么iis上部署,请参考我前面的博文 2.HTML代码 <!DOCTYPE html> <html ...

  4. git生成public key

    1 配置user name和email git config --global user.name "xxx" git config --global user.email &qu ...

  5. 矩阵乘法 NOI2012的一道题

    今天,kzj大佬教了我矩阵加速. 让我以这篇随笔表示感谢吧! 这是我刷的一道题:NOI2012 随机数据生成器. 就是普通的矩阵加速,只是要注意的是: 直接用乘法会爆long long,可以参考一下 ...

  6. python3的时间日期处理

    1.python3日期和时间 Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时 ...

  7. READ_TEXT

    [转自http://lz357502668.blog.163.com/blog/static/1649674320109119101907/]这里,定义ITAB内表来存储长文本,并放到内表ITAB_E ...

  8. grunt小教程

    本人的博客写了grunt的小教程,从零开始,一步一步的通过例子讲解,希望喜欢的同学给我的github上加颗星,谢谢! github地址: https://github.com/manlili/grun ...

  9. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  10. 【LeetCode】删除链表的倒数第N个节点

    给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 ...