Transmitters
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4955   Accepted: 2624

Description

In a wireless network with multiple transmitters sending on the same frequencies, it is often a requirement that signals don't overlap, or at least that they don't conflict. One way of accomplishing this is to restrict a transmitter's coverage area. This problem uses a shielded transmitter that only broadcasts in a semicircle.

A transmitter T is located somewhere on a 1,000 square meter grid.
It broadcasts in a semicircular area of radius r. The transmitter may be
rotated any amount, but not moved. Given N points anywhere on the grid,
compute the maximum number of points that can be simultaneously reached
by the transmitter's signal. Figure 1 shows the same data points with
two different transmitter rotations.



All input coordinates are integers (0-1000). The radius is a
positive real number greater than 0. Points on the boundary of a
semicircle are considered within that semicircle. There are 1-150 unique
points to examine per transmitter. No points are at the same location
as the transmitter.

Input

Input
consists of information for one or more independent transmitter
problems. Each problem begins with one line containing the (x,y)
coordinates of the transmitter followed by the broadcast radius, r. The
next line contains the number of points N on the grid, followed by N
sets of (x,y) coordinates, one set per line. The end of the input is
signalled by a line with a negative radius; the (x,y) values will be
present but indeterminate. Figures 1 and 2 represent the data in the
first two example data sets below, though they are on different scales.
Figures 1a and 2 show transmitter rotations that result in maximal
coverage.

Output

For
each transmitter, the output contains a single line with the maximum
number of points that can be contained in some semicircle.

Sample Input

25 25 3.5
7
25 28
23 27
27 27
24 23
26 23
24 29
26 29
350 200 2.0
5
350 202
350 199
350 198
348 200
352 200
995 995 10.0
4
1000 1000
999 998
990 992
1000 999
100 100 -2.5

Sample Output

3
4
4 题意:半圆围绕圆心旋转能够覆盖平面内最多的点
题解:先去掉所有和圆心距离大于r的点,然后我们以每一点和圆心组成的线段为边界来计算线段两边的点,比较出最大值就好了.记得赋值最大值的时候要赋值为0,因为它有可能不会进循环。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const double eps = 1e-;
struct Point{
double x,y;
}p[N],circle;
struct Line{
Point a,b;
}line;
double r;
int n;
int cross(Point a,Point b,Point c){
double ans = (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
if(fabs(ans)<eps) return ;
if(ans<) return ;
return -;
}
int main(){
while(true){
scanf("%lf%lf%lf",&circle.x,&circle.y,&r);
if(r<=) break;
scanf("%d",&n);
int k = ;
for(int i=;i<n;i++){
double x,y;
scanf("%lf%lf",&x,&y);
if((x-circle.x)*(x-circle.x)+(y-circle.y)*(y-circle.y)>r*r) continue;
p[k].x = x;
p[k++].y = y;
}
int temp1 ,temp2,mx = ; ///mx要赋值为0,因为有可能一个点都没有,习惯赋值成-1被坑了一把
for(int i=;i<k;i++){
line.a = p[i];
line.b = circle;
temp1=temp2 =;
for(int j=;j<k;j++){
if(cross(p[j],line.a,line.b)==) {
temp1++;
temp2++;
}else if(cross(p[j],line.a,line.b)==){
temp1++;
}else temp2++;
}
int ans = max(temp1,temp2);
mx = max(ans,mx);
}
printf("%d\n",mx);
}
return ;
}

poj 1106(半圆围绕圆心旋转能够覆盖平面内最多的点)的更多相关文章

  1. Poj 1106 Transmitters

    Poj 1106 Transmitters 传送门 给出一个半圆,可以任意旋转,问这个半圆能够覆盖的最多点数. 我们枚举每一个点作为必然覆盖点,那么使用叉积看极角关系即可判断其余的点是否能够与其存在一 ...

  2. html5 canvas围绕中心点旋转

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Unity摄像机围绕物体旋转两种实现方式

    第一种,使用Transform 函数 RotateAround. 代码如下: public Transform target;//获取旋转目标 private void camerarotate() ...

  4. IOS 以随意点为圆心 旋转UIView

    环绕底边中点旋转                     UIView本身是支持旋转的,能够用UIView.transform属性实现旋转. The origin of the transform i ...

  5. “全栈2019”Java第一百零一章:局部内部类覆盖作用域内成员详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  6. n个点m条有向边,求在入度为零的点到n号点的所有路 //径中,哪条边被这些路径覆盖的次数最多

    //n个点m条有向边,求在入度为零的点到n号点的所有路 //径中,哪条边被这些路径覆盖的次数最多 //有关DAG的知识,先记个模板 #include<iostream> #include& ...

  7. poj 1106 Transmitters (枚举+叉积运用)

    题目链接:http://poj.org/problem?id=1106 算法思路:由于圆心和半径都确定,又是180度,这里枚举过一点的直径,求出这个直径的一个在圆上的端点,就可以用叉积的大于,等于,小 ...

  8. poj 1106 Transmitters (叉乘的应用)

    http://poj.org/problem?id=1106 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4488   A ...

  9. poj 3020 Antenna Placement(最小路径覆盖 + 构图)

    http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

随机推荐

  1. Java与Scala的两种简易版连接池

    Java版简易版连接池: import java.sql.Connection; import java.sql.DriverManager; import java.util.LinkedList; ...

  2. 后端接口迁移(从 webapi 到 openapi)前端经验总结

    此文已由作者张磊授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 前情提要 以前用的是 webapi 现在统一切成 openapi,字段结构统统都变了 接入接口 20+,涉及模 ...

  3. 软引用SoftReference

    本文介绍对象的强.软.弱和虚引用的概念.应用及其在UML中的表示. 1.对象的强.软.弱和虚引用 在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有 ...

  4. 剑指Offer - 九度1391 - 顺时针打印矩阵

    剑指Offer - 九度1391 - 顺时针打印矩阵2013-11-24 04:55 题目描述: 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 ...

  5. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目6

    2014-03-20 03:27 题目:输出所有由N对括号组成的合法的括号序列.比如n=2,“()()”.“(())”等等. 解法:动态规划配合DFS,应该也叫记忆化搜索吧.一个整数N总可以拆成若干个 ...

  6. java中封装的概念

    封装(Encapsulation)是类的三大特性之一, 就是将类的状态信息隐藏在类的内部,不允许外部程序直接访问, 而是通过该类提供的方法来实现对隐藏信息的操作和访问. 简而言之,就是隐藏内部实现,提 ...

  7. iOS笔记059 - 网络总结

    网络 基本概念 客户端:client 服务器:server 请求:request 响应:response 过程 客户端 -> 发送请求 -> 服务器(连接数据库) 服务器 -> 发送 ...

  8. 给vmstat加上时间戳

    vmstat -n 5 | awk '{print strftime("[%Y-%m-%d %H:%M:%S]"),$0}' 或者 vmstat -n 5 | awk '{ pri ...

  9. Scala 基础(3)—— 基础类型和基础操作

    1. Scala 的一些基础类型 Scala 提供了 8 种基础类型,对应 Java 的 8 种基本数据类型. 其中包括: 整数类型:Byte, Short, Int, Long, Char 浮点类型 ...

  10. 使用hadoop统计多个文本中每个单词数目

    程序源码 import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Con ...