usaco rect1

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int dmax=2001,maxn=10001;
int a[1501][1501];
int x[maxn],ux[maxn],y[maxn],uy[maxn];
struct node{
	int x,y,x1,y1;
	int color;
};
struct node data[maxn];
bool t1[maxn],t2[maxn];
int ans[maxn];

int main(){
	int i,j,k,m,n;
	int flag=0;
	freopen("rect1.in","r",stdin);
	freopen("rect1.out","w",stdout);
	scanf("%d%d%d",&n,&m,&k);
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++)
			a[i][j]=1;
	t1[0]=1,t2[0]=1;
	t1[n]=1,t2[m]=1;
	for (i=1;i<=k;i++){
		scanf("%d%d%d%d%d",&data[i].x,&data[i].y,&data[i].x1,&data[i].y1,&data[i].color);
		t1[data[i].x]=1,t1[data[i].x1]=1;
		t2[data[i].y]=1,t2[data[i].y1]=1;
	}
	for (i=0;i<=n;i++){
		if (t1[i]==1){
			x[++flag]=i;
			ux[i]=flag;
		}
	}
	flag=0;
	for (i=0;i<=m;i++){
		if (t2[i]==1){
			y[++flag]=i;
			uy[i]=flag;
		}
	}
	int o;
	for (o=1;o<=k;o++){
		for (i=ux[data[o].x]+1;i<=ux[data[o].x1];i++)
			for (j=uy[data[o].y]+1;j<=uy[data[o].y1];j++)
				a[i][j]=data[o].color;
	}
	for (i=1;i<=ux[n];i++)
		for (j=1;j<=uy[m];j++)
			ans[a[i][j]]+=(x[i]-x[i-1])*(y[j]-y[j-1]);
	for (i=1;i<=2500;i++)
		if (ans[i])
			printf("%d %d\n",i,ans[i]);
	return 0;
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yalishiyanzhouyu888/article/details/50659619
上一篇usaco pprime
下一篇usaco sprime
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭