标签:
input | output |
---|---|
20 20 3 2 2 18 18 2 0 8 19 19 3 8 0 10 19 4 |
1 91 2 84 3 187 4 38 |
分析:经典的覆盖问题,参考http://blog.csdn.net/skyprophet/article/details/4514926,冰块上浮法;
倒序计算,在计算到当前矩形时,看在他上面的矩形有没有重叠的,有就去掉那个部分,一直递归下去即可;
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, rt<<1 #define Rson mid+1, R, rt<<1|1 const int maxn=3e3+10; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} int n,m,k,t,ans[maxn]; struct node { int x1,x2,y1,y2,c; node(){} node(int _x1,int _x2,int _y1,int _y2,int _c) { x1=_x1,x2=_x2,y1=_y1,y2=_y2,c=_c; } }op[maxn]; int get(node p,int nt) { int ans=0; while(nt<=k&&((p.x1>=op[nt].x2)||(p.x2<=op[nt].x1)||(p.y1>=op[nt].y2)||(p.y2<=op[nt].y1))) nt++; if(nt>k)return (p.x2-p.x1)*(p.y2-p.y1); if(p.x1<op[nt].x1) ans+=get(node(p.x1,op[nt].x1,p.y1,p.y2,op[nt].c),nt+1),p.x1=op[nt].x1; if(p.x2>op[nt].x2) ans+=get(node(op[nt].x2,p.x2,p.y1,p.y2,op[nt].c),nt+1),p.x2=op[nt].x2; if(p.y1<op[nt].y1) ans+=get(node(p.x1,p.x2,p.y1,op[nt].y1,op[nt].c),nt+1),p.y1=op[nt].y1; if(p.y2>op[nt].y2) ans+=get(node(p.x1,p.x2,op[nt].y2,p.y2,op[nt].c),nt+1),p.y2=op[nt].y2; return ans; } int main() { int i,j; scanf("%d%d%d",&n,&m,&k); ans[1]=n*m; rep(i,1,k)scanf("%d%d%d%d%d",&op[i].x1,&op[i].y1,&op[i].x2,&op[i].y2,&op[i].c); for(i=k;i>=1;i--) { ans[op[i].c]+=(j=get(op[i],i+1)); ans[1]-=j; } rep(i,1,2500)if(ans[i])printf("%d %d\n",i,ans[i]); //system("Pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5867574.html