#include <iostream>
#include <cstdio>
using namespace std;
int n,m,w = 0, turn = 1;
int main(){
while ( scanf("%d %d",&n,&m)==2 ){
int arr_H[10][10]={{0,0}}, arr_V[10][10]={{0,0}};
//存入数据
for ( int q=0; q<m; q++ ){
char ch;
int i,j;
cin >> ch >> i >> j;
if ( ch=='H' ) arr_H[i-1][j-1] = 1;
else arr_V[j-1][i-1] = 1;
}
//以边长遍历
int count[10]={0}, ist = 0;
for ( int j=1; j<=n; j++ ){
ist ++;
//以位置遍历
for ( int x=0; x<n-j; x++ ){
for ( int y=0; y<n-j; y++ ){
//判断是否是正方形
int judge = 1;
for ( int k=0; k<=j; k++ )
if ( !arr_H[x+k][y] || !arr_V[x][y+k] ) judge = 0;
if ( judge ) count[ist]++;
}
}
}
if ( w ) printf("\n**********************************\n\n");
printf("Problem #%d\n\n",turn++);
int judge = 1;
for ( int i=1; i<=n; i++ ){
if ( count[i]!=0 ){
printf("%d square (s) of size %d\n",count[i],i);
judge = 0;
}
}
if ( judge ) printf("No completed squares can be found.\n");
w = 1;
}
return 0;
}
整体思路是用两个数组,arr_H[] arr_V[]来保存横线和竖线,遍历每一个正方形的左上角顶点。count数组表示每个尺寸正方形的数量。我拿测试样例和自己想的样例,用别人ac代码和我的代码运行,结果都一样,但我的提交显示wa