例题20

来源:互联网 发布:基因编程技术 编辑:程序博客网 时间:2024/05/16 05:13

能交题的传送门

题解:把模型建立出来还是很好想的,就是求在某一时刻,被扫到线段的条数个数最多。

代码:

#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<set>using namespace std;struct node{    double x;    int type;    bool operator < (const node &t)const{        return x<t.x||(x==t.x&&type>t.type);    }}even[200010];void solo(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(){    int t;    scanf("%d",&t);    while(t--)    {        int w,h,n;        int ge=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;            double R=1e9;            solo(x,a,w,L,R);            solo(y,b,h,L,R);            if(R>L)            {                even[ge++]=(node){L,0};                even[ge++]=(node){R,1};            }        }            sort(even,even+ge);            int ans=0,cnt=0;            for(int i=0;i<ge;i++)            {                if(even[i].type==0)                    ans=max(ans,++cnt);                else                    cnt--;            }            printf("%d\n",ans);        }    }



0 0
原创粉丝点击