#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstring>
#define MAX_LEN 1000
using namespace std;
int number[MAX_LEN], n , m ;
char map[MAX_LEN][MAX_LEN];
int JudgeV(int x,int y){
if(map[x][y]=='A'||map[x][y]=='V')
return 1;
else return 0;
}
int JudgeH(int x,int y){
if(map[x][y]=='A'||map[x][y]=='H')
return 1;
else return 0;
}
int main()
{
freopen("in.txt","r",stdin);
// cout<<number[10]<<endl;
int count=0;
while(scanf("%d %d",&n,&m)!=EOF){
if(count) cout<<endl<<"**********************************"<<endl<<endl;
count++;
memset(map,'0',sizeof(map));
memset(number,0,sizeof(number));
for(int i=0;i<m;i++){
char point;
int x,y;
scanf(" %c %d %d",&point,&x,&y);
if(point=='H')
if(map[x][y]=='0')
map[x][y]=point;
else
map[x][y]='A';
if(point=='V')
if(map[y][x]=='0')
map[y][x]=point;
else
map[y][x]='A';
// cout<<map[x][y]<<endl;
}
for(int p=1;p<=n;p++){
for(int q=1;q<=n;q++){
if(map[p][q]=='A'){
// cout<<p<<' '<<q<<endl;
for(int begin1=p+1,begin2=q+1;begin1<=n&&begin2<=n;begin1++,begin2++){
int flag=1;
for(int be=0;be<begin1-p;be++){
if(!JudgeV(p+be,begin2)||!JudgeH(begin1,q+be)){
flag=0;
break;
}
}
if(flag)
number[begin1-p]++;
if(JudgeH(p,begin2)&&JudgeV(begin1,q))
continue;
else break;
}
}
}
}
cout<<"Problem #"<<count<<endl<<endl;
int num=0;
for(int i=1;i<MAX_LEN;i++){
if(number[i]!=0){
num++;
cout<<number[i]<<" square (s) of size "<<i<<endl;
}
}
if(!num) cout<<"No completed squares can be found."<<endl;
}
return 0;
}
Squares(UVA-201)
于 2023-05-31 20:21:44 首次发布