-
Notifications
You must be signed in to change notification settings - Fork 1
/
E1.cpp
111 lines (84 loc) · 2.25 KB
/
E1.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node {
ll x, y, sz;
node(ll _x, ll _y, ll _sz) {
x = _x;
y = _y;
sz = _sz;
}
};
vector <node> ans;
char grid[105][105];
bool check[105][105];
int main()
{
ll n, m;
cin >> n >> m;
for(ll i = 1; i <= n; i++) {
scanf("%s", grid[i] + 1);
}
for(ll i = 2; i < n; i++) {
for(ll j = 2; j < m; j++) {
//cout << grid[i][j];
if(grid[i][j] != '*')
continue;
ll cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
for(ll k = j - 1; k >= 1; k--) {
if(grid[i][k] != '*')
break;
cnt1++;
}
//cout << 5;
for(ll k = j + 1; k <= m; k++) {
if(grid[i][k] != '*')
break;
cnt2++;
}
for(ll k = i - 1; k >= 1; k--) {
if(grid[k][j] != '*')
break;
cnt3++;
}
for(ll k = i + 1; i <= n; k++) {
if(grid[k][j] != '*')
break;
cnt4++;
}
ll cnt = min(cnt1, cnt2);
cnt = min(cnt3, cnt);
cnt = min(cnt4, cnt);
if(cnt == 0)
continue;
check[i][j] = 1;
ans.push_back( node(i, j, cnt));
for(ll k = j - 1, l = 1; l <= cnt; k--, l++) {
check[i][k] = 1;
}
for(ll k = j + 1, l = 1; l <= cnt; k++, l++) {
check[i][k] = 1;
}
for(ll k = i - 1, l = 1; l <= cnt; k--, l++) {
check[k][j] = 1;
}
for(ll k = i + 1, l = 1; l <= cnt; k++, l++) {
check[k][j] = 1;
}
}
//cout <<endl;
}
for(ll i = 1; i <= n; i++) {
for(ll j = 1; j <= m; j++) {
if(grid[i][j] == '*' && check[i][j] == 0) {
printf("-1\n");
return 0;
}
}
}
cout << ans.size() << endl;
for(ll i = 0; i < ans.size(); i++) {
printf("%lld %lld %lld\n", ans[i].x, ans[i].y, ans[i].sz);
}
return 0;
}