Is there any strange input??
Here is my code(maybe there is some problem in it,BTW,I use DP)
Code: Select all
#include <stdio.h>
#include <math.h>
void main()
{
/* freopen("out.txt","w",stdout);
freopen("in.txt","r",stdin);*/
int dot;
int lines;
char temp;
int x,y;
bool cv[10][10];
bool ch[10][10];
int v[10][10];
int h[10][10];
int i,j,k,l;
int cases=0;
int count=0;
int flag=0;
while(scanf("%d",&dot)!=EOF)
{
scanf("%d",&lines);
cases++;
if(cases!=1)
printf("n**********************************nn");
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
cv[i][j]=0;
ch[i][j]=0;
v[i][j]=0;
h[i][j]=0;
}
}
for(i=0;i<lines;i++)
{
scanf("%s %d %d",&temp,&x,&y);
if(temp=='H')
ch[x-1][y-1]=1;
else if(temp=='V')
cv[y-1][x-1]=1;
}
for(i=0;i<dot;i++)
for(j=0;j<dot;j++)
for(k=0;k<j;k++)
h[i][j]=h[i][j]+(int)fabs(ch[i][k]-1);
for(i=0;i<dot;i++)
for(j=0;j<dot;j++)
for(k=0;k<i;k++)
v[i][j]=v[i][j]+(int)fabs(cv[k][j]-1);
printf("Problem #%dnn",cases);
flag=0;
for(i=1;i<dot;i++)
{
count=0;
for(j=0;j<dot-i;j++)
for(k=0;k<dot-i;k++)
if(h[j][k+i]-h[j][k]==0&&h[j+i][k+i]-h[j+i][k]==0)
if(v[j][k]-v[j+i][k]==0&&v[j][k+i]-v[j+i][k+i]==0)
count++;
if(count!=0)
{
flag=1;
printf("%d square (s) of size %dn",count,i);
}
}
if(flag==0)
printf("No completed squares can be found.n");
}
}