算法竞赛入门经典第四章习题4-2 Squares UVA - 201
2018-01-04 16:01
579 查看
习题4-2
https://vjudge.net/problem/UVA-201
https://vjudge.net/problem/UVA-201
#include<iostream> #include<string> #include<cstring> #pragma warning(disable:4996) using namespace std; int main() { #ifdef _DEBUG freopen("in", "rb", stdin); #endif // _DEBUG int N, M, cnt = 0; while (cin >> N >> M) { int H[10][10] = {}, V[10][10] = {}; if (++cnt != 1)printf("\n**********************************\n\n"); printf("Problem #%d\n\n", cnt); while (M--) { string s; int a, b; cin >> s >> a >> b; switch (s[0]) { case 'H':H[a][b] = 1; break; case 'V':V[b][a] = 1; break; default: break; } } bool flag = true;//是否没有正方形 for (int k = 1; k <= N-1; ++k) {//k为边长 int nn = 0;//边长为k的正方形个数 for (int i = 1; i + k <= N; ++i) { for (int j = 1; j + k <= N; ++j) { bool is_z = true; for (int x = 0; x < k; ++x) if (!(H[i][j + x] && H[i + k][j + x] && V[i + x][j] && V[i + x][j + k])) { is_z = false; break; } if (is_z) ++nn; } } if (nn) { flag = false; printf("%d square (s) of size %d\n", nn, k); } } if (flag) printf("No completed squares can be found.\n"); } }
相关文章推荐
- 算法竞赛入门经典第四章习题
- 算法竞赛入门经典第四章习题4-6 Morse Mismatches UVA - 508
- 算法竞赛入门经典第四章习题4-3 Othello UVA - 220
- 习题 4-2 Squares UVa 201
- 算法竞赛入门经典第四章习题4-10 Flooded! UVA - 815
- 算法竞赛入门经典第四章习题4-5 IP Networks UVA - 1590
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 算法竞赛入门经典(第2版)习题4-2 正方形 Squares UVa201
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 例题+习题(15/16)
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 算法竞赛入门经典第四章 【uvaoj在线习题(二)】
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- UVa201 Squares(算法竞赛入门经典第二版习题4-2)
- 紫书章四习题 2 Squares UVA - 201 (找有几个正方形)
- 算法竞赛入门经典第四章:部分习题解答
- 算法竞赛入门经典(第2版)习题4-2 正方形UVa201