HRBUST - 2385 方方正正【暴力过】【待正规做法】

http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2385

魔法阵 :四角的符号都一样

给n行m列 有多少个魔法阵

#include <iostream>
#include <cstdio>

using namespace std;


int main() {
	int t;
	scanf("%d", &t);
	getchar();
	while (t--) {
		int n, m;
		scanf("%d%d", &n, &m);
		getchar();
		long long sum = 0;
		char maze[110][110];
		for (int i = 1; i <= n; ++i) {
			cin.getline(maze[i] + 1, m + 1, '\n');
			//cin >> maze[i] + 1;
		}
		
	/*	for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				cout << maze[i][j];
			}
			cout << endl;
		}*/
		
		for (int row = 1; row <= n - 1; ++row) {
			for (int rr = 1; rr <= m - 1; ++rr) {
				for (int lie = row + 1; lie <= n; ++lie) {
					if (maze[row][rr] == maze[lie][rr]) {//看左上角和右上相不相同
						for (int ll = rr + 1; ll <= m; ++ll) {
							if (maze[row][rr] == maze[lie][ll] && maze[row][rr] == maze[row][ll])//再比较左下和右下
								sum++;
						}
					}
				}
			}
		}
		printf("%lld\n", sum);
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/liangnimahanwei/article/details/83097670