• Bzoj2732 [HNOI2012]射箭


    Time Limit: 10 Sec  Memory Limit: 128 MB
    Submit: 2952  Solved: 962

    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


    数据再加一组---2017.3.25

    Source

    数学问题 计算几何 半平面交 二分答案

    如果有一条抛物线可以穿过靶子,那么它需要满足$y1<=ax^2+bx+c<=y2$

    由于抛物线一定经过原点,所以c可以省掉。每个靶子的x都是已知的,可以看做常量。

    把a当做自变量,b当做因变量,上式转化成直线方程,问题转化为在平面直角坐标系中最多能放下前多少个靶子确定的直线,使得它们围成的半平面非空。

    可以二分答案然后check(好像不可以不二分答案)

    素闻此题卡精度丧心病狂,怂了一波拍了一阵子才交,结果还是WA掉了。

    “数据已加强”

    看了感觉真害怕

    感谢liurunda分享的诸多坑点和测试数据

    →  http://www.cnblogs.com/liu-runda/p/6439792.html

    面向数据编程终于过了

      1 /*by SilverN*/
      2 #include<algorithm>
      3 #include<iostream>
      4 #include<cstring>
      5 #include<cstdio>
      6 #include<cmath>
      7 #include<vector>
      8 using namespace std;
      9 const double pi=acos(-1.0);
     10 const double eps=1e-10;
     11 const double INF=1e12;
     12 const int mxn=200010;
     13 int read(){
     14     int x=0,f=1;char ch=getchar();
     15     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
     16     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
     17     return x*f;
     18 }
     19 struct point{
     20     double x,y;
     21     point operator + (point b){return (point){x+b.x,y+b.y};};
     22     point operator - (point b){return (point){x-b.x,y-b.y};};
     23     point operator * (double v){return (point){x*v,y*v};}
     24     point operator / (double v){return (point){x/v,y/v};}
     25 }p[mxn];
     26 typedef point Vector;
     27 inline int DT(double x){
     28     if(fabs(x)<eps)return 0;
     29     return x<0?-1:1;
     30 }
     31 inline double dot (point &a,point &b){return a.x*b.x+a.y*b.y;}
     32 inline double Cross(point a,point b){
     33     return a.x*b.y-a.y*b.x;
     34 }
     35 inline double dist(point a,point b){
     36     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
     37 }
     38 int n;
     39 struct Line{
     40     point x;
     41     Vector v;
     42     double alpha;
     43     int id;
     44     void getang(){
     45         alpha=atan2(v.y,v.x);
     46         if(alpha<0)alpha+=pi*2;
     47     }
     48     bool operator < (Line b)const{
     49         return alpha<b.alpha;
     50     }
     51 }a[mxn];
     52 int m=0;
     53 bool Right(Line &a,point b){
     54     return DT(Cross(a.v,b-a.x))<0;
     55 }
     56 point Linesec(Line a,Line b){
     57     point x=a.x-b.x;
     58     double t=Cross(b.v,x)/Cross(a.v,b.v);
     59     return a.x+a.v*t;
     60 }
     61 int hd,tl,q[mxn];
     62 void insert(int i){
     63     while(hd<tl && Right(a[i],p[tl-1]))tl--;
     64     while(hd<tl && Right(a[i],p[hd]))hd++;
     65     q[++tl]=i;
     66     if(hd<tl && DT(a[q[tl]].alpha-a[q[tl-1]].alpha)==0)tl--;//排除极角相同的直线
     67     if(hd<tl)p[tl-1]=Linesec(a[q[tl]],a[q[tl-1]]);
     68     return;
     69 }
     70 bool solve(int lim){
     71 //    printf("mid:%d
    ",lim);
     72     hd=1;tl=0;
     73     for(int i=1;i<=m;i++){
     74         if(a[i].id<=lim){
     75             insert(i);
     76         }
     77     }
     78     while(hd<tl && Right(a[q[hd]],p[tl-1]))tl--;
     79     return tl-hd>=2;
     80 }
     81 int main(){
     82     int i,j,x,y1,y2;
     83     n=read();
     84     a[++m].x=(point){0,0};a[m].v=(Vector){INF,0};a[m].id=0;a[m].getang();
     85 //    a[++m].x=(point){-INF,-INF};a[m].v=(Vector){1,0};a[m].id=0;a[m].getang();
     86     a[++m].x=(point){-eps,0};a[m].v=(Vector){0,INF};a[m].id=0;a[m].getang();
     87 //    a[++m].x=(point){INF,-INF};a[m].v=(Vector){0,1};a[m].id=0;a[m].getang();
     88     a[++m].x=(point){0,INF};a[m].v=(Vector){-1,0};a[m].id=0;a[m].getang();
     89     a[++m].x=(point){-INF,0};a[m].v=(Vector){0,-1};a[m].id=0;a[m].getang();
     90     //划分边界 
     91     for(i=1;i<=n;i++){
     92         x=read();y1=read();y2=read();
     93         a[++m].x=(point){0,(double)y1/x};a[m].v=(Vector){1,-x};
     94         a[m].id=i;a[m].getang();
     95         a[++m].x=(point){0,(double)y2/x};a[m].v=(Vector){-1,x};
     96         a[m].id=i;a[m].getang();
     97     }
     98     sort(a+1,a+m+1);
     99     int l=1,r=n,res=0;
    100     while(l<=r){
    101         int mid=(l+r)>>1;
    102         if(solve(mid)){
    103             res=mid;
    104             l=mid+1;
    105         }
    106         else r=mid-1;
    107     }
    108     printf("%d
    ",res);
    109     return 0;
    110 }
  • 相关阅读:
    Performance and Design
    返回数组中不重复的元素
    IE的button元素bug
    (转)Google Closure: 糟糕的JavaScript
    Why do we have an IMG element?
    About this and that
    C#中的Attribute
    C#检查字体是否存储,以及安装
    ZipFile压缩文件后,解压文件后有多层目录的处理方法
    Office系列在线预览
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6686391.html
Copyright © 2020-2023  润新知