简单的矩形切割,前面有说过这种方法,是window那道题
/*
ID:xsy97051
LANG:C++
TASK:rect1
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a,b,n,color[2505],cnt[2505],llx[2505],lly[2505],urx[2505],ury[2505];
void qiege(int xs,int ys,int xt,int yt,int d,int c)
{
while((xs>=urx[d] || ys>=ury[d] || xt<=llx[d] || yt<=lly[d]) && d<=n)
d++;
if (d==n+1)
{
cnt[c]+=(yt-ys)*(xt-xs);
return ;
}
if(xs<llx[d])
{
qiege(xs,ys,llx[d],yt,d+1,c);
xs=llx[d];
}
if(xt>urx[d])
{
qiege(urx[d],ys,xt,yt,d+1,c);
xt=urx[d];
}
if(ys<lly[d]) qiege(xs,ys,xt,lly[d],d+1,c);
if(yt>ury[d]) qiege(xs,ury[d],xt,yt,d+1,c);
return;
}
int main()
{
freopen("rect1.in","r",stdin);
freopen("rect1.out","w",stdout);
cin>>a>>b>>n;
memset(cnt,0,sizeof(cnt));
color[1]=1;
llx[1]=0;lly[1]=0;urx[1]=a;ury[1]=b;
n++;
for(int i=2;i<=n;i++)
cin>>llx[i]>>lly[i]>>urx[i]>>ury[i]>>color[i];
for(int i=n;i>=1;i--)
qiege(llx[i],lly[i],urx[i],ury[i],i+1,color[i]);
for(int i=1;i<=2500;i++)
if(cnt[i]) cout<<i<<" "<<cnt[i]<<endl;
return 0;
}