时间44 ms
击败
84.52%
内存8.6 MB
击败
34.52%
解题思路:暴力枚举
class Solution {
public:
vector<int> bestCoordinate(vector<vector<int>>& towers, int radius) {
int n = towers.size();
double currMax = 0.0;
vector<int>res = {0,0};
for(int x = 0; x <=50 ;x++){
for(int y = 0 ; y <=50 ; y++){
double curr = 0.0;
for(vector<int>&tower :towers){
int x1 = tower[0];
int y1 = tower[1];
int q = tower[2];
double d= pow((x-x1)*(x-x1)+(y-y1)*(y-y1),0.5);
if(d<=(double)radius){
curr += floor((double)q/(d+1));
}
}
if(curr >currMax){
currMax = curr;
res = {x,y};
}
}
}
return res;
}
};