zoukankan      html  css  js  c++  java
  • LA3905

    题意:

    给出n颗流星,第i颗在第T秒时飞到(xi+ai*t,yi+bi*t),给出一个矩形,问在某一时刻这个矩形中的流星数目最多有多少

    题解:

    首先计算出每一颗流星经过时间

    然后左端点移动,计算出少了一颗流星还是多了一颗流星

    代码:

    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const int N=200005;
    double A[N];
    int x,y,a,b,n,T,w,h,tot,B[N],F[N];
    int cmp(int x,int y)
    {
        if (A[x]==A[y])return B[x]<B[y];
        return A[x]<A[y];
    }
    void update(int x,int a,int w,double& L,double& R)
    {
       if(a==0){if(x<=0||x>=w)R=L-1;}
       else if(a>0)
        {
          L=max(L,-(double)x/a);
          R=min(R,(double)(w-x)/a);
        }
       else
        {
          L=max(L,(double)(w-x)/a);
          R=min(R,-(double)x/a); 
        }         
    }
    int main()
    {
        scanf("%d",&T);
        while (T--)
         {
             scanf("%d%d%d",&w,&h,&n);
             tot=0;
             while (n--)
              {
                  double t1=0,t2=1e9;
                  scanf("%d%d%d%d",&x,&y,&a,&b);
                  update(x,a,w,t1,t2);
                  update(y,b,h,t1,t2);
                  if (t1>=t2)continue;
                  A[++tot]=t1;B[tot]=1;F[tot]=tot;
                  A[++tot]=t2;B[tot]=-1;F[tot]=tot;
              }
             sort(F+1,F+tot+1,cmp);
             int now=0,q=0;
            for (int i=1;i<=tot;i++)
             {
                 now+=B[F[i]];
                 q=max(now,q);
             } 
            printf("%d
    ",q); 
         }
    }
  • 相关阅读:
    循序渐进学习XHTML
    一些常用正则表达式
    输入框限制
    Oracle 取随机数
    安装部署中的数据库打包和快捷方式启动浏览器
    游标小例
    查询列数
    临时表简介
    Update动态更新
    sql 多列转一列
  • 原文地址:https://www.cnblogs.com/xuanyiming/p/7858152.html
Copyright © 2011-2022 走看看