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(); } }
相关文章推荐
- 【解题报告】POJ-1106 Transmitters
- POJ 1106 Transmitters
- POJ1106-Transmitters
- (poj step8.1.1.1)POJ 1106 Transmitters(判断一条边在另一条边的哪一个方向——计算叉积)
- POJ 1106 Transmitters 已被翻译
- POJ 1106 Transmitters
- poj 1106 Transmitters
- POJ-1106 Transmitters解题报告
- POJ 1106 Transmitters
- POJ 1106 Transmitters(离散化)
- POJ 1106 Transmitters 计算几何
- ZOJ 1041(POJ 1106) Transmitters(…
- poj 1106 Transmitters (叉乘的应用)
- POJ 1106 Transmitters
- POJ 1106 Transmitters(计算几何:叉积)
- poj 1106 Transmitters (枚举+叉积运用)
- poj1106 Transmitters
- poj 1106 Transmitters (计算几何,叉积||极角排序)
- POJ 1106 Transmitters
- poj 1106 Transmitters