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 ...
随机推荐
- jquery取值赋值
("#A").val("1") id为A的值就是1了 jQuery中都这样,赋值的时候作为参数传给函数,和单纯的js有区别,像 $("#A" ...
- Erlang OTP学习:supervisor [转]
转自: http://diaocow.iteye.com/blog/1762895 今天细致的看了下supervisor,现在做个总结: 其中,方块代表supervisor process,它的功能很 ...
- 《Cracking the Coding Interview》——第1章:数组和字符串——题目5
2014-03-18 01:40 题目:对字符串进行类似游程编码的压缩,如果压缩完了长度更长,则返回不压缩的结果.比如:aabcccccaaa->a2b1c5a3,abc->abc. 解法 ...
- 《数据结构》C++代码 Splay
Splay,伸展树.之所以先写这个课内并不怎么常用的数据结构,是因为本人非常喜欢Splay,我觉得这是非常有美感且灵活的一种平衡树.在此先声明,我的伸展树写法来源于CLJ大牛,基础好的同学可以去他的博 ...
- Windows+Python 3.6环境下安装PyQt4
第一步:下载.whl,地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4,这里可以下载不同的python版本对应的包. 第二步:选择一个目录,将下 ...
- try-catch-finally容易犯的错误
测试环境 JDK1.8 1. catch中包含return //有return的时候 输出13423 //无return的时候 输出134234 public class Trycatch { pub ...
- 立体匹配之Census Transform
1.立体匹配算法主要可分为两大类:基于局部约束和基于全局约束的立体匹配算法. (一)基于全局约束的立体匹配算法:在本质上属于优化算法,它是将立体匹配问题转化为寻找全局能量函数的最优化问题,其代表算法主 ...
- 一个画ROC曲线的封装包
Draw_ROC_Curves This is a python file which is used for drawing ROC curves -f : assign file name -t ...
- kafak基本操作
创建topic bin/kafka-topics.sh --create --zookeeper 192.168.1.81:2181 --replication-factor 3 -partition ...
- SQL 基础笔记(一)
本笔记整理自<SQL 基础教程>.<MySQL 必知必会>和网上资料.个人笔记不保证正确. 一.基础 SQL,即结构化查询语言,是为访问与操作关系数据库中的数据而设计的语言. ...