拿到题目先看数据范围, 1 - 50,直接爆搜,本来还以为用dfs...
class Solution {
public:
vector<int> bestCoordinate(vector<vector<int>>& towers, int radius)
{
int max1 = 0;
vector<int> ans = {0,0};
for(int i = 0;i < 51;i ++)
{
for(int j = 0; j < 51; j ++)
{
int temp = 0;
for(auto & t : towers) //枚举该坐标离每一个塔的距离和信号
{
double d = sqrt((t[0] - i) * (t[0] - i) + (t[1] - j) * (t[1] - j));
if(d <= radius)
{
temp += floor(t[2] / (1 + d));
}
}
if(max1 < temp) //找到最大的信号地
{
max1 = temp;
ans = {i,j};
}
}
}
return ans;
}
};