bzoj5045: 打砖块 (粗制滥造)

来源:互联网 发布:淘宝双11怎么修改价格 编辑:程序博客网 时间:2024/05/19 09:17

辣鸡题解

题意

就是打砖块
问你最多可以打多少砖块

题解

暴力维护一下有什么砖块被打了就好了

CODE:

#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<algorithm>using namespace std;typedef long long LL;const LL N=100005;LL n;inline LL read(){    LL x=0,f=1;char ch=getchar();    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}    return x*f;}struct qq{    LL x,y1,y2;    bool operator < (qq a) const    {        if (a.x!=x) return a.x<x;        if (a.y1!=y1) return a.y1<y1;        return a.y2>y2;    }}a[N];priority_queue<qq> q;int main(){    n=read();    for (LL u=1;u<=n;u++)        a[u].x=read(),a[u].y1=a[u].y2=read(),q.push(a[u]);    LL ans=0;    while (!q.empty())    {         qq a=q.top();q.pop();         while (!q.empty())         {             qq b=q.top();             if (a.y2+2>=b.y1&&a.x==b.x)             {                a.y2=max(a.y2,b.y2);                q.pop();             }             else break;         }         ans=ans+((a.y2-a.y1)/2+1);         if (a.y1!=a.y2)         {            qq b=a;            b.x++;b.y1++;b.y2--;            q.push(b);         }    }    printf("%lld\n",ans);    return 0;}
原创粉丝点击