# LEETCODE 1453. Maximum Number of Darts Inside of a Circular Dartboard 解题思路分析

```输入：points = [[-2,0],[2,0],[0,2],[0,-2]], r = 2

```输入：points = [[-3,0],[3,0],[2,6],[5,4],[0,9],[7,8]], r = 5

```输入：points = [[-2,0],[2,0],[0,2],[0,-2]], r = 1

```输入：points = [[1,2],[3,5],[1,-1],[2,3],[4,1],[1,3]], r = 2

• 1 <= points.length <= 100
• points[i].length == 2
• -10^4 <= points[i][0], points[i][1] <= 10^4
• 1 <= r <= 5000

```public int numPoints(int[][] points, int r) {
int n = points.length;
int res = 1;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
double[] a = new double[]{points[i][0], points[i][1]};
double[] b = new double[]{points[j][0], points[j][1]};
double[] center = findCenter(a, b, (double)r);
if(!Double.isNaN(center[0]) && !Double.isNaN(center[1])){
int cur = 2;
for(int k=0; k<n; k++) if(k!=i && k!=j){
if(dist(center, new double[]{points[k][0], points[k][1]})<=r){
cur++;
}
}
res = Math.max(res, cur);
}
}
}
return res;
}

public double[] findCenter(double[] a, double[] b, double r) {
double[] mid = new double[2];
double[] res = new double[2];
mid[0]=(a[0]+b[0])/2;
mid[1]=(a[1]+b[1])/2;
double angle = Math.atan2(a[0]-b[0],b[1]-a[1]);
double d = Math.sqrt(r*r-Math.pow(dist(a,mid),2));
res[0] = mid[0]+d*Math.cos(angle);
res[1] = mid[1]+d*Math.sin(angle);
return res;
}

public double dist(double[] a, double[] b){
return Math.sqrt(Math.pow(a[0]-b[0],2) + Math.pow(a[1]-b[1],2));
}```

Runtime: 29 ms, faster than 100.00% of Java online submissions for Maximum Number of Darts Inside of a Circular Dartboard.

Memory Usage: 39.3 MB, less than 100.00% of Java online submissions for Maximum Number of Darts Inside of a Circular Dartboard.