记录编号 84263 评测结果 AAAAAAAA
题目名称 求图形面积 最终得分 100
用户昵称 Gravatar超级傲娇的AC酱 是否通过 通过
代码语言 C++ 运行时间 0.022 s
提交时间 2013-12-10 23:37:12 内存使用 0.32 MiB
显示代码纯文本
/*
Designed by CH.Genius_King
on 2013/12/10
22:45
*/
#include<iostream>
#include<deque>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int way[8][2]={{-1,0},{1,0},{0,-1},{0,1},{1,1},{1,-1},{-1,-1},{-1,1}},A[32][32],La,Lb,n;
struct Pair
{
	int first,second;
	bool operator < (const Pair& x) const
	{
		return first<x.first;
	}
};
int BFS(int,int,int);
void init();
int main()
{
	freopen("area.out","w",stdout);
	int i,j;
	vector<Pair>C;
	init();
	for(i=0;i<La;i++)
		for(j=0;j<Lb;j++)
			if(A[i][j]!=0)
			{
				int Rc=A[i][j];
				C.push_back((Pair){Rc,BFS(i,j,Rc)});
			}
	//sort(C.begin(),C.end());
    while(C.size()!=0)
	{
		vector<Pair>::iterator it;
		it=min_element(C.begin(),C.end());
		cout<<(*it).first<<' '<<(*it).second<<endl;
		C.erase(it);
	}
	//for(i=0;i<C.size();i++)
		//fo<<C[i].first<<' '<<C[i].second<<endl;
	return 0;
}
void init()
{
	freopen("area.in","r",stdin);
	ios::sync_with_stdio(false);
	int x1,x2,y1,y2,c,i,j,k;
	cin>>La>>Lb>>n;
	for(j=Lb-1;j>=0;j--)
		for(i=La-1;i>=0;i--)
			A[i][j]=1;
	for(i=0;i<n;i++)
	{
		cin>>x1>>y1>>x2>>y2>>c;
		for(j=x1+La/2;j<x2+La/2;j++)
			for(k=y1+Lb/2;k<y2+Lb/2;k++)
				A[j][k]=c;
	}
}
int BFS(int Px,int Py,int Col)
{
	int posx,posy,i,Ans=1;
	deque<int>x,y;
	x.push_back(Px);y.push_back(Py);
	A[Px][Py]=0;
	while(!x.empty()&&!y.empty())
	{
		for(i=0;i<8;i++)
		{
			posx=x[0]+way[i][0];
			posy=y[0]+way[i][1];
			if(posx>=0&&posx<La&&posy>=0&&posy<Lb)
				if(A[posx][posy]==Col)
				{
					A[posx][posy]=0;
					x.push_back(posx);
					y.push_back(posy);
					Ans++;
				}
		}
		x.pop_front();
		y.pop_front();
	}
	return Ans;
}