Uva-Live 3905-Meteor

来源:互联网 发布:傲飞数据整合工具 编辑:程序博客网 时间:2024/05/16 18:59

要求求出最多能看到多少流行,计算流行进入和出去的时间,然后排序遍历一次即可。

代码:

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=1e6;int w,h,n,e;struct node{    double t;    int type;    bool operator < (const node &a) const    {return t==a.t?type>a.type:t<a.t;    }}eve[maxn];void update(int x,int v,int w,double &L,double &R){    if(v==0)    {if(x<=0||x>=w) R=L-1;    }    else if(v>0)    {L=max(L,-(double)x/v);R=min(R,(double)(w-x)/v);    }    else    {L=max(L,(double)(w-x)/v);R=min(R,-(double)x/v);    }}int main(){    int cas;    scanf("%d",&cas);    while(cas--)    {e=0;scanf("%d%d%d",&w,&h,&n);for(int i=0;i<n;i++){    int x,y,a,b;    scanf("%d%d%d%d",&x,&y,&a,&b);    double L=0,R=1e8;    update(x,a,w,L,R);    update(y,b,h,L,R);    if(R>L)    {eve[e++]=(node){L,0};eve[e++]=(node){R,1};    }}sort(eve,eve+e);int ans=0,cnt=0;for(int i=0;i<e;i++){    if(eve[i].type==0)ans=max(ans,++cnt);    elsecnt--;}printf("%d\n",ans);    }    return 0;}




原创粉丝点击