2732: [HNOI2012]射箭

2732: [HNOI2012]射箭

Time Limit: 10 Sec   Memory Limit: 128 MB
Submit: 1966   Solved: 676
[ Submit][ Status][ Discuss]

Description

沫沫最近在玩一个二维的射箭游戏,如下图 1 所示,这个游戏中的 x 轴在地面,第一象限中有一些竖直线段作为靶子,任意两个靶子都没有公共部分,也不会接触坐标轴。沫沫控制一个位于(0,0)的弓箭手,可以朝 0 至 90?中的任意角度(不包括 0度和 90度),以任意大小的力量射出带有穿透能力的光之箭。由于游戏中没有空气阻力,并且光之箭没有箭身,箭的轨迹会是一条标准的抛物线,被轨迹穿过的所有靶子都认为被沫沫射中了,包括那些 只有端点被射中的靶子。这个游戏有多种模式,其中沫沫最喜欢的是闯关模式。在闯关模式中,第一关只有一个靶 子,射中这个靶子即可进入第二关,这时在第一关的基础上会出现另外一个靶子,若能够一箭 双雕射中这两个靶子便可进入第三关,这时会出现第三个靶子。依此类推,每过一关都会新出 现一个靶子,在第 K 关必须一箭射中前 K 关出现的所有 K 个靶子才能进入第 K+1 关,否则游戏 结束。沫沫花了很多时间在这个游戏上,却最多只能玩到第七关“七星连珠”,这让她非常困惑。 于是她设法获得了每一关出现的靶子的位置,想让你告诉她,最多能通过多少关

Input

输入文件第一行是一个正整数N,表示一共有N关。接下来有N行,第i+1行是用空格隔开的三个正整数xi,yi1,yi2(yi1<yi2 ),表示第i关出现的靶子的横坐标是xi,纵坐标的范围是从yi1到yi2 。 
 输入保证30%的数据满足N≤100,50%的数据满足N≤5000,100%的数据满足N≤100000且给 出的所有坐标不超过109 。 
 

Output


仅包含一个整数,表示最多的通关数。

Sample Input

5
2 8 12
5 4 5
3 8 10
6 2 3
1 3 7

Sample Output

3

HINT



数据已加强By WWT15。特鸣谢!---2015.03.09

Source

[ Submit][ Status][ Discuss]

对于每个靶子 转换为 y1 <= ax^2 + bx <= y2
这样是两个不等式,两个半平面
然后二分答案判定半平面有没有交集

写的时候一开始半平面方向搞反,然后。。。日了狗了向量数乘那个常数居然用int(MDZZ)?!!!

#include<iostream>  
#include<cstdio>  
#include<cstdlib>  
#include<algorithm>  
#include<cstring>  
#include<cmath>  
#include<vector>  
#include<queue>  
using namespace std;  
  
typedef double DB;  
const int maxn = 1E5 + 10;  
const DB B = 1;  
const DB eps = 1E-10;  
  
struct Point{  
    DB x,y;  
      
    Point operator - (const Point &b) {return (Point){x - b.x,y - b.y};}  
      
    Point operator + (const Point &b) {return (Point){x + b.x,y + b.y};}  
      
    Point operator * (const DB &b) {return (Point){x*b,y*b};}  
      
}p[maxn*2];  
typedef Point Vector;  
  
struct Line{  
    Point P; Vector v;  
    DB ang;  
    Line() {}  
    Line(Point P,Vector v): P(P),v(v){ang = atan2(v.y,v.x);}  
      
    bool operator < (const Line &b) const {  
        return ang < b.ang;  
    }     
}q[maxn*2],L[maxn*2];  
  
int n;  
DB x[maxn],ya[maxn],yb[maxn];  
  
DB Cross(Vector v,Vector w) {return v.x*w.y - v.y*w.x;}  
  
bool Onleft(Line L,Point P) {return Cross(L.v,P - L.P) > 0;}  
  
Point GetIntersection(Line a,Line b)  
{  
    Vector u = a.P - b.P;  
    DB t = Cross(b.v,u)/Cross(a.v,b.v);  
    Point po = a.P + a.v*t; return po;  
}  
  
bool Judge(int now)  
{  
    int cnt = 0; if (now == 1) return 1;  
    for (int i = 1; i <= now; i++) {  
        DB X = x[i]*x[i];  
        L[cnt++] = Line((Point){B,-B/x[i] + ya[i]/X},(Vector){B,-B/x[i]});  
        L[cnt++] = Line((Point){B,-B/x[i] + yb[i]/X},(Vector){-B,B/x[i]});  
    }  
    sort(L,L + cnt);  
    int first,last; q[first = last = 0] = L[0];  
    for (int i = 1;  i < cnt; i++) {  
        while (first < last && !Onleft(L[i],p[last-1])) --last;  
        while (first < last && !Onleft(L[i],p[first])) ++first;  
        q[++last] = L[i];  
        if (fabs(Cross(q[last].v,q[last-1].v)) < eps) {  
            --last;  
            if (Onleft(q[last],L[i].P)) q[last] = L[i];  
        }  
        if (first < last) p[last-1] = GetIntersection(q[last-1],q[last]);  
    }  
    while (first < last && !Onleft(q[first],p[last-1])) --last;  
    return last - first > 1;  
}  
  
int main()  
{  
    #ifdef YZY  
           freopen("yzy.txt","r",stdin);  
    #endif  
      
    cin >> n;  
    for (int i = 1; i <= n; i++) scanf("%lf%lf%lf",&x[i],&ya[i],&yb[i]);  
    int l,r; l = 0,r = n;  
    while (r - l > 1) {  
        int mid = (l + r) >> 1;  
        if (Judge(mid)) l = mid;  
        else r = mid;  
    }  
    if (Judge(r)) cout << r;  
    else cout << l;  
    return 0;  
}  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值