forked from chencorey/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLighthouse.cpp
More file actions
62 lines (59 loc) · 1.07 KB
/
Lighthouse.cpp
File metadata and controls
62 lines (59 loc) · 1.07 KB
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
// https://www.hackerrank.com/contests/w23/challenges/lighthouse
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool arr[50][50];
int N;
bool checkValid(int X, int Y, int r)
{
for (int i = 0; i <= r; i++)
{
int left = X - i;
int right = X + i;
int dy = sqrt(r*r - i*i);
int low = Y - dy;
int high = Y + dy;
for(int j = left; j<=right; j++)
{
if(!arr[j][low]||!arr[j][high])return false;
}
for(int j = low; j<=high; j++)
{
if(!arr[left][j]||!arr[right][j])return false;
}
}
return true;
}
int main() {
cin >> N;
for (int i = 0; i<N; i++)
{
for (int j = 0; j<N; j++)
{
char c;
cin >> c;
arr[i][j] = (c == '.');
}
}
int best = 0;
for (int i = 0; i<N; i++)
{
for (int j = 0; j<N; j++)
{
int k = 0;
bool valid = true;
while (i + k<N&&i - k >= 0 && j + k<N&&j - k >= 0 && valid)
{
valid = checkValid(i, j, k);
k++;
}
if (!valid)k--;
best = max(best, k - 1);
}
}
cout << best;
return 0;
}