首页 > 代码库 > UVa 201 - Squares
UVa 201 - Squares
题目:给你一个由点组成的网格,再给一些连结相邻点的操作(横向、纵向),统计里面的正方形。
分析:模拟。直接用两个数组,记录横线和竖线,统计时枚举顶点扫描即可。
说明:先输出小的╮(╯▽╰)╭。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int H[10][10]; int V[10][10]; int main() { int n,m,x,y,T = 0; char c; while (~scanf("%d%d",&n,&m)) { getchar(); for (int i = 1 ; i <= n ; ++ i) for (int j = 1 ; j <= n ; ++ j) V[i][j] = H[i][j] = 0; for (int i = 1 ; i <= m ; ++ i) { scanf("%c%d%d",&c,&x,&y); getchar(); if (c == 'H') H[x][y] = 1; else V[y][x] = 1; } if (T ++) printf("\n**********************************\n\n"); printf("Problem #%d\n\n",T); int sum = 0; for (int l = 1 ; l <= n ; ++ l) { int count = 0,flag = 0; for (int i = 1 ; i+l <= n ; ++ i) for (int j = 1 ; j+l <= n ; ++ j) { flag = 1; for (int h = j ; h < j+l ; ++ h) if (!H[i][h] || !H[i+l][h]) flag = 0; for (int v = i ; v < i+l ; ++ v) if (!V[v][j] || !V[v][j+l]) flag = 0; count += flag; } sum += count; if (count) printf("%d square (s) of size %d\n",count,l); } if (!sum) printf("No completed squares can be found.\n"); } return 0; }
UVa 201 - Squares
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。