http://acm.bnu.edu.cn/v3/contest_show.php?cid=5772#problem/B
给你一个由点组成的网格,再给一些连结相邻点的操作(横向、纵向),统计里面的正方形,从小到大输出其数量。
水题,依次枚举边长,判断每个点为左上角时能否构成正方形..
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <map> #include <iostream> #include <sstream> #include <algorithm> using namespace std; #define RD(x) scanf("%d",&x) #define RD2(x,y) scanf("%d%d",&x,&y) #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) #define clr0(x) memset(x,0,sizeof(x)) #define clr1(x) memset(x,-1,sizeof(x)) #define eps 1e-9 const double pi = acos(-1.0); typedef long long LL; const int inf = 1000000000; const int maxn = 15; int h[maxn][maxn],v[maxn][maxn],n,m; int main() { int _ = 0; while(~RD2(n,m)){ int x,y; char typ[2]; clr0(h),clr0(v); while(m--){ scanf("%s",typ); RD2(x,y); if(typ[0] == 'H') h[x][y] = 1; else v[y][x] = 1; } if(_++) puts("\n**********************************\n"); printf("Problem #%d\n\n",_); int sum = 0; for(int l = 1;l <= n;++l){ int cnt = 0; for(int i = 1;i + l <= n;++i) for(int j = 1;j + l <= n;++j){ int flag = 1; for(int hh = j;hh < j + l;++hh) if(!h[i][hh] || !h[i+l][hh]) flag = 0; for(int vv = i;vv < i + l;++vv) if(!v[vv][j] || !v[vv][j+l]) flag = 0; cnt += flag; } sum += cnt; if(cnt) printf("%d square (s) of size %d\n",cnt,l); } if(!sum) puts("No completed squares can be found."); } return 0; }