Squares UVA - 201
错误总结:
不看题,最后输出出问题,疯狂错
思路:
将坐标x y变成一个值——(x-1)*列数+y,利用二维数组存储边,最后暴力。
Code:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, m, i, j, x, y, z, to = 0, k = 0, gram[100][100], su[10];
while (cin >> m >> n) {
to = 0;memset(gram, 0, sizeof(gram)); memset(su, 0, sizeof(su));
for (i = 0; i < n; i++) {
char a; cin >> a >> x >> y;
if (a == 'H')gram[(x - 1) * m + y][(x - 1) * m + (y + 1)] = gram[(x - 1) * m + (y + 1)][(x - 1) * m + y] = 1;
else gram[x + m * (y - 1)][x + m * y] = gram[x + m * y][x + m * (y - 1)] = 1;
}
for (i = 1; i < m; i++)
for (j = 1; j < m; j++)
for (x = 1; x <= m - max(i, j); x++)
for (y = z = 1; y <= x; su[x] += (y == x && z - 1 == 4 * x ? to = 1 : 0), y++)
z += (gram[(i - 1) * m + (j + y - 1)][(i - 1) * m + (j + y)] + gram[(i - 1 + y - 1) * m + (j + x)][(i - 1 + y) * m + (j + x)] + gram[(i - 1 + x) * m + (j + x - y + 1)][(i - 1 + x) * m + (j + x - y)] + gram[(i - 1 + x - y + 1) * m + j][(i - 1 + x - y) * m + j]);
if (k)cout << "\n**********************************\n\n";
cout << "Problem #" << ++k << endl << endl;
for (i = 1; i <= m; i++)if (su[i])cout << su[i] << " square (s) of size " << i << endl;
if (!to)cout << "No completed squares can be found." << endl;
}
}