hdu5714

先开始我是思考在每行的情况忽略了小明这个关键因素,这题的关键就是注意一个技巧将分散的变量集中在一个点上这是一个常用技巧。。

注意在离散化话一下。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int dir[2][40000],all[40000];
struct pos
{
    int kind,addkind,p;
};
int t,n,tot;
pos q[80050];
bool com(pos a,pos b)
{
  return a.p<b.p;
}
int main()
{
    scanf("%d",&t);
    int k=1;
    while(t--)
    {
        tot=0;
       scanf("%d",&n);
       while(n--)
       {
           int x,y,z,d;
           scanf("%d%d%d%d",&x,&y,&z,&d);
           if(z*2<(y-x))continue;
           if(d==1)
           {
               q[tot].p=y-z;
               q[tot].kind=1;
               q[tot++].addkind=1;
               q[tot].p=x+z+1;
               q[tot].kind=1;
               q[tot++].addkind=-1;
           }
           else
           {
               q[tot].p=x+z;
               q[tot].kind=0;
               q[tot++].addkind=1;
               q[tot].p=y-z-1;
               q[tot].kind=0;
               q[tot++].addkind=-1;
           }
       }
           sort(q,q+tot,com);
           int endpos=0;
           for(int i=0;i<tot;i++)
           {
               if(i!=0&&q[i].p>q[i-1].p)
                endpos++;
               dir[q[i].kind][endpos]+=q[i].addkind;
           }
           int ans=0;
           for(int i=0;i<=endpos;i++)
           {
               ans+=dir[1][i];
               all[i]=ans;
           }
           int maxx=-1;
           ans=0;
           for(int i=endpos;i>=0;i--)
           {
               ans+=dir[0][i];
               maxx=max(ans,maxx);
               all[i]+=maxx;
           }
           maxx=-1;
           for(int i=0;i<=endpos;i++)
            maxx=max(all[i],maxx);
            printf("Case #%d:\n%d\n",k++,maxx);
           for(int i=0;i<=endpos;i++)
            {
                all[i]=0;
                dir[0][i]=0;
                dir[1][i]=0;
            }
       }
         return 0;
    }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值