poj 1106(半圆围绕圆心旋转能够覆盖平面内最多的点)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 4955 | Accepted: 2624 |
Description
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
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
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(半圆围绕圆心旋转能够覆盖平面内最多的点)的更多相关文章
- Poj 1106 Transmitters
Poj 1106 Transmitters 传送门 给出一个半圆,可以任意旋转,问这个半圆能够覆盖的最多点数. 我们枚举每一个点作为必然覆盖点,那么使用叉积看极角关系即可判断其余的点是否能够与其存在一 ...
- html5 canvas围绕中心点旋转
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Unity摄像机围绕物体旋转两种实现方式
第一种,使用Transform 函数 RotateAround. 代码如下: public Transform target;//获取旋转目标 private void camerarotate() ...
- IOS 以随意点为圆心 旋转UIView
环绕底边中点旋转 UIView本身是支持旋转的,能够用UIView.transform属性实现旋转. The origin of the transform i ...
- “全栈2019”Java第一百零一章:局部内部类覆盖作用域内成员详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- n个点m条有向边,求在入度为零的点到n号点的所有路 //径中,哪条边被这些路径覆盖的次数最多
//n个点m条有向边,求在入度为零的点到n号点的所有路 //径中,哪条边被这些路径覆盖的次数最多 //有关DAG的知识,先记个模板 #include<iostream> #include& ...
- poj 1106 Transmitters (枚举+叉积运用)
题目链接:http://poj.org/problem?id=1106 算法思路:由于圆心和半径都确定,又是180度,这里枚举过一点的直径,求出这个直径的一个在圆上的端点,就可以用叉积的大于,等于,小 ...
- poj 1106 Transmitters (叉乘的应用)
http://poj.org/problem?id=1106 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4488 A ...
- poj 3020 Antenna Placement(最小路径覆盖 + 构图)
http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
随机推荐
- 使用阿里开源工具 TProfiler 在海量业务代码中精确定位性能代码 (jvm性能调优)
技术交流群:233513714 本文是<JVM 性能调优实战之:一次系统性能瓶颈的寻找过程> 的后续篇,该篇介绍了如何使用 JDK 自身提供的工具进行 JVM 调优将 TPS 由 2.5 ...
- 洛谷P1331 海战
海战 题目链接 这还是一道联通块的题,只是需要判断是否存在以下四种情况: o. .o oo oo oo oo o. .o 如果存在就是Bad placement. 要注意标记以下,不然会出现多次输出B ...
- windows 定时任务 - 定时关机
添加定时关机,刚好可以利用windows定时任务 [开始]->[控制面板]->[任务计划]->[添加任务计划] 1.找到 shutdown.exe 设置每天执行 2.设置晚上10点 ...
- 通过广播关闭应用程序(每个Activity)和连续点击两次返回键关闭应用程序
对于一个应用程序可能有很多个Activity,可能每个人并不想一个个的去关闭Activity,也有可能忘了,那怎么关闭所有的未关闭的Activity呢,其实有很多方法,但是我最喜欢的一种就是通过广播事 ...
- Google Chrome 自定义协议(PROTOCOL)问题的处理
最近在使用谷歌浏览器的时候遇到了自定义协议(PROTOCOL)的问题,比较折腾,特此记录,希望我浪费生命换来的结果能够帮助读到此文的朋友少浪费一点宝贵的时间! 由于某些原因,电脑里一直没有安装阿里旺旺 ...
- 《Cracking the Coding Interview》——第17章:普通题——题目12
2014-04-29 00:04 题目:给定一个整数数组,找出所有加起来为指定和的数对. 解法1:可以用哈希表保存数组元素,做到O(n)时间的算法. 代码: // 17.12 Given an arr ...
- Windows下如何解决git bash的默认home目录路径问题
转自:http://blog.csdn.net/lucien_zhou/article/details/62069246 为了解决这个问题,我在网上找了好久,尝试过按网上其他人所述,修改 git 安装 ...
- [OpenCV]Mat类详解
http://blog.csdn.net/yang_xian521/article/details/7107786 Preface Mat:Matrix Mat类可以被看做是opencv中C++版本的 ...
- Python——数据类型之str
本篇主要内容: 1.str元素的访问 2.str内置43个方法使用示例 str就是储存各种东西的字符串. 他的方法也是最多的...有各种各样的神奇魔法. 1.str的访问,str可以想列表那样访问每一 ...
- Tomcat 顶层结构
Tomcat中最顶层的容器叫Server,代表整个服务器,Server中包含至少一个Service,用于具体提供服务. Service主要包含两部分:Connector 和 Container ...