zoukankan      html  css  js  c++  java
  • Poj 1106 Transmitters

    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[N];
    
    	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();
    	}
    }
    
  • 相关阅读:
    java接口定义和作用
    8-12接口测试进阶-2源码分析
    接口测试3-4使用csv进行接口测试
    接口测试3-3Excel格式
    接口测试3-2csv格式
    java study2
    接口测试进阶3-1数据驱动测试
    java study1
    REST-assured 3发送图片
    codeforces 659C C. Tanya and Toys(水题+map)
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/6797289.html
Copyright © 2011-2022 走看看