题目大意:
以雷达心为圆心的半圆形雷达覆盖范围有多个点 雷达可旋转,求最多覆盖数(含在边界的)
解题思路:
枚举每个点,然后叉积计算在左边l的和右边r的和共线的个数m。然后每次取 m a x ( l , r ) + m max(l,\ r)\ +\ m max(l, r) + m
Accepted code:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
double r;
int sx, sy, n, nm, ans, x[10001], y[10001];
int main() {
do {
int j, k, left, right, m;
scanf("%d %d %lf", &sx, &sy, &r);
if (r < 0) break;
scanf("%d", &n);
nm = ans = 0;
memset(x, 0, sizeof x);
memset(y, 0, sizeof y);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &j, &k);
if (sqrt((j-sx) * (j-sx) + (k-sy) * (k-sy)) <= r) {
nm++;
x[nm] = j;
y[nm] = k;
}
}
for (int i = 1; i <= nm; i++) {
left = right = 0;
for (int j = 1; j <= nm; j++) {
m = (x[i]-sx) * (y[j]-sy) - (y[i]-sy) * (x[j]-sx);
if (m >= 0) ++right;
if (m <= 0) ++left;
}
ans = max(ans, max(left, right));
}
printf("%d\n", ans);
} while(1);
return 0;
}