题目:1620. 网络信号最好的坐标
思路:暴力搜索
class Solution {
public:
vector<int> bestCoordinate(vector<vector<int>>& towers, int radius) {
int minx=INT_MAX,maxx=INT_MIN,miny=INT_MAX,maxy=INT_MIN;
int resx=0,resy=0;
int distance = 0;
for(auto x:towers){
minx=min(minx,x[0]);
maxx=max(maxx,x[0]);
miny=min(miny,x[1]);
maxy=max(maxy,x[1]);
}
for(int i=minx;i<=maxx;++i){
for(int j=miny;j<=maxy;++j){
int temp = 0;
for(auto x:towers){
int multi = (x[0]-i)*(x[0]-i)+(x[1]-j)*(x[1]-j);
if(multi<=radius*radius)
temp += (int)((double)x[2]/(1+sqrt(multi)));
}
if(temp>distance){
resx=i;
resy=j;
distance=temp;
}
}
}
return {resx,resy};
}
};