输入样例
10 10 2 5
0 0
7 0
输出样例
57
代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int W = scan.nextInt(); //长
int H = scan.nextInt(); //高
int n = scan.nextInt(); //位置的数量
int r = scan.nextInt(); //半径
int[][] arr = new int[W + 1][H + 1]; //将矩形区域的点放入数组
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
arr[i][j] = -1; //赋值为-1
}
}
for (int i = 0; i < n; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
for (int j = 0; j < W + 1; j++) {
for (int k = 0; k < H + 1; k++) {
int l = (j - x) * (j - x) + (k - y) * (k - y); //通过点到圆点的距离来判断是否在圆内
if (l <= r * r) {
arr[j][k] = 1; //赋值为1
}
}
}
}
int count = 0;
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (arr[i][j] == 1) {
count++; //统计值为1的数量
}
}
}
System.out.println(count);
}
}