Skip to content

Commit 86a51cb

Browse files
authored
Create 2101.Detonate-the-Maximum-Bombs.cpp
1 parent 4487405 commit 86a51cb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using LL = long long;
2+
class Solution {
3+
vector<int>next[100];
4+
public:
5+
int maximumDetonation(vector<vector<int>>& bombs)
6+
{
7+
int n = bombs.size();
8+
for (int i=0; i<n; i++)
9+
for (int j=0; j<n; j++)
10+
{
11+
LL dx = bombs[i][0]-bombs[j][0];
12+
LL dy = bombs[i][1]-bombs[j][1];
13+
LL r = bombs[i][2];
14+
if (dx*dx+dy*dy<=r*r)
15+
next[i].push_back(j);
16+
}
17+
18+
int ret = 0;
19+
for (int s=0; s<n; s++)
20+
{
21+
queue<int>q;
22+
q.push(s);
23+
vector<int>visited(n);
24+
visited[s] = 1;
25+
while (!q.empty())
26+
{
27+
int cur = q.front();
28+
q.pop();
29+
for (int i: next[cur])
30+
{
31+
if (visited[i]) continue;
32+
q.push(i);
33+
visited[i] = 1;
34+
}
35+
}
36+
int count = 0;
37+
for (int i=0; i<n; i++)
38+
count+=visited[i];
39+
ret = max(count, ret);
40+
}
41+
return ret;
42+
43+
}
44+
};

0 commit comments

Comments
 (0)