题解:数据范围小,直接暴力枚举所有点,然后计算贡献,取最大值即可
class Solution {
public int[] bestCoordinate(int[][] towers, int radius) {
int n = towers.length;
int max = 0;
int x = 100;
int y = 100;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
int temp = 0;
for (int[] tower : towers) {
int x1 = tower[0];
int y1 = tower[1];
int d = (i - x1) * (i - x1) + (j - y1) * (j - y1);
if (d <= radius * radius) {
temp += tower[2] / (1 + Math.sqrt(d));
}
}
if (temp > max) {
max = temp;
x = i;
y = j;
}
if (temp == max) {
if (i < x) {
x = i;
y = j;
}
if (i == x && j < y) {
y = j;
}
}
}
}
return new int[]{x, y};
}
}
标签:1620,int,max,towers,坐标,信号,y1,100,x1
From: https://www.cnblogs.com/eiffelzero/p/16852986.html