您的位置:首页 > 其它

Poj 1106 Transmitters

2017-05-02 17:38 337 查看

Poj 1106 Transmitters

传送门


给出一个半圆,可以任意旋转,问这个半圆能够覆盖的最多点数。

我们枚举每一个点作为必然覆盖点,那么使用叉积看极角关系即可判断其余的点是否能够与其存在一个半圆内


import java.io.*;
import java.util.*;

public class Main {
static class Point implements Comparable<Point> {
double x, y;

@Override
public int compareTo(Point a) {
return (int) cross(a);
}

public double cross(Point a) {
return a.x * y - x * a.y;
}
}

static double cross(Point st, Point a, Point b) {
return (a.x - st.x) * (b.y - st.y) - (b.x - st.x) * (a.y - st.y);
}

static double dist(Point a1, Point a2) {
return (a1.x - a2.x) * (a1.x - a2.x) + (a1.y - a2.y) * (a1.y - a2.y);
}

static final int N = 10005;
static final int inf = 0x3f3f3f3f;
static final double eps = 1e-9;
static Point a[] = new Point
;

public static void main(String[] args) {
Scanner cin = new Scanner(new InputStreamReader(System.in));
while (cin.hasNext()) {
Point st = new Point(), tmp = new Point();
st.x = cin.nextDouble();
st.y = cin.nextDouble();
double r = cin.nextDouble();
double d;
int n = cin.nextInt();
int cnt = 0;
for (int i = 0; i < n; i++) {
tmp.x = cin.nextDouble();
tmp.y = cin.nextDouble();
d = dist(st, tmp);
if (d < r * r || Math.abs(d - r * r) < eps) {
cnt++;
if (a[cnt] == null)
a[cnt] = new Point();
a[cnt].x = tmp.x;
a[cnt].y = tmp.y;
}
}
int ans = 0;
for (int i = 1; i <= cnt; i++) {
int count = 1;
for (int j = 1; j <= cnt; j++) {
if (i != j && cross(st, a[i], a[j]) <= 0)
count++;
}
if (count > ans)
ans = count;
}
System.out.println(ans);
}
cin.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: