以前做的题,写的丑,肯定可以优化,但是做过的题不想再看了,直接粘代码。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
bool fuc(int x,int y,int i);
int h[20][20]={},v[20][20]={};
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,cnt=0;
while(cin>>n)
{
memset(h,0,sizeof(h));
memset(v,0,sizeof(v));
++cnt;
int num;
cin>>num;
while(num--)
{
char c;
int a,b;
cin>>c>>a>>b;
if(c=='H')
h[a][b]=1;
else
v[b][a]=1;
}
//cout<<fuc(1,1,1)<<endl;
int sum[20]={};
for(int i=1;i<=n-1;i++)
{
for(int ii=1;ii<=n-i;ii++)
{
for(int jj=1;jj<=n-i;jj++)
{
if(fuc(ii,jj,i))
{
sum[i]++;
}
}
}
}
if(cnt>1)
{
cout<<"\n**********************************\n\n";
}
cout<<"Problem #"<<cnt<<"\n\n";
bool flag=0;
for(int i=1;i<=n-1;i++)
{
if(sum[i]>0)
{
flag=1;
cout<<sum[i]<<" square (s) of size "<<i<<endl;
}
}
if(flag==0)
{
cout<<"No completed squares can be found."<<endl;
}
}
}
bool fuc(int x,int y,int i)
{
for(int jj=y;jj<=y+i-1;jj++)
{
if(h[x][jj]==0||h[x+i][jj]==0)
{
return 0;
}
}
for(int ii=x;ii<=x+i-1;ii++)
{
if(v[ii][y]==0||v[ii][y+i]==0)
{
return 0;
}
}
return 1;
}