forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquare_detector.cpp
More file actions
48 lines (44 loc) · 972 Bytes
/
square_detector.cpp
File metadata and controls
48 lines (44 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
int n;
bool run() {
vector<pair<int, int> > mm;
cin >> n;
string str;
REP(i,n) {
cin >> str;
REP(j,n) {
if (str[j] == '#') mm.push_back(make_pair(i, j));
}
}
int m = mm.size();
if (m <= 1) return true;
int q = sqrt(m + 0.5);
if (q * q != m) {
return false;
}
int idx = 0, sx = mm[0].first, sy = mm[0].second;
REP(i,q) {
REP(j,q) {
if (mm[idx].first != sx + i || mm[idx].second != sy + j) return false;
++idx;
}
}
return true;
}
int main() {
int kase;
cin >> kase;
FOR(i,1,kase) {
cout << "Case #" << i << ": ";
if (run()) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}