10703 - Free spots
#include<bits/stdc++.h>
using namespace std;
bool arr[510][510];
void reset()
{
for(int k=0;k<=508;k++)
memset(arr[k],false,sizeof(arr[k]));
}
int mx(int a, int b)
{
return (a>b)? a:b;
}
int mn(int a, int b)
{
return (a<b)? a:b;
}
int main()
{
//freopen("in.txt","r",stdin);
int W,H,N;
while(scanf("%d%d%d",&W,&H,&N)!=EOF)
{
if(W==0 && H==0 && N==0) break;
reset();
int i,j,x1,y1,x2,y2,l,m,points=0;
for(i=1;i<=N;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int X1,Y1,X2,Y2;
X1=mn(x1,x2);
Y1=mn(y1,y2);
X2=mx(x1,x2);
Y2=mx(y1,y2);
for(j=X1;j<=X2;j++)
{
for(l=Y1;l<=Y2;l++)
{
arr[j][l]=true;
}
}
}
for(i=1;i<=W;i++)
{
for(j=1;j<=H;j++)
{
if(arr[i][j]==false) points++;
}
}
if ( points == 0 ) printf ("There is no empty spots.\n");
else if ( points == 1 ) printf ("There is one empty spot.\n");
else printf ("There are %d empty spots.\n", points);
}
return 0;
}
No comments