Phone CellTime Limit:10000MS    Memory Limit:32768KB    64bit IO Format:%lld
& %llu

Description

Nowadays, everyone has a cellphone, or even two or three. You probably know where their name comes from. Do you. Cellphones can be moved (they are "mobile") and they use wireless connection to static stations called BTS (Base Transceiver Station). Each BTS
covers an area around it and that area is called a cell.

The Czech Technical University runs an experimental private GSM network with a BTS right on top of the building you are in just now. Since the placement of base stations is very important for the network coverage, your task is to create a program that will
find the optimal position for a BTS. The program will be given coordinates of "points of interest". The goal is to find a position that will cover the maximal number of these points. It is supposed that a BTS can cover all points that are no further than some
given distance R. Therefore, the cell has a circular shape.

The picture above shows eight points of interest (little circles) and one of the possible optimal BTS positions (small triangle). For the given distance
R, it is not possible to cover more than four points. Notice that the BTS does not need to be placed in an existing point of interest.

Input

The input consists of several scenarios. Each scenario begins with a line containing two integer numbers
N and R. N is the number of points of interest, 1 <=
N
<= 2000. R is the maximal distance the BTS is able to cover, 0 <= R < 10000. Then there are
N lines, each containing two integer numbers Xi,
Yi
giving coordinates of the i-th point, |Xi|, |Yi| < 10000. All points are distinct, i.e., no two of them will have the same coordinates.

The scenario is followed by one empty line and then the next scenario begins. The last one is followed by a line containing two zeros.

A point lying at the circle boundary (exactly in the distance R) is considered covered. To avoid floating-point inaccuracies, the input points will be selected in such a way that for any possible subset of points
S that can be covered by a circle with the radius R + 0.001, there will always exist a circle with the radius R that also covers them.

Output

For each scenario, print one line containing the sentence "It is possible to cover M points.", where
M is the maximal number of points of interest that may be covered by a single BTS.

Sample Input

8 2
1 2
5 3
5 4
1 4
8 2
4 5
7 5
3 3 2 100
0 100
0 -100 0 0

Sample Output

It is possible to cover 4 points.
It is possible to cover 2 points.

Notes

The first sample input scenario corresponds to the picture, providing that the X axis aims right and Y axis down.

本来模版中有个n^2算法的。可是超时。赛后百度了一下。还有nlogn算法的。

那么也能够当作模版来用了。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm> using namespace std ; const double eps = 1e-8 ;
const double PI = acos(-1.0) ;
int n ;
double r ; struct point
{
double x,y ;
}p[2010] ;
struct node
{
double angle ;
int flag ;
}q[4030] ; inline int dcmp(double d)
{
return d < -eps ? -1 : d > eps ;
}
bool cmp(const node &a,const node &b)//角度区间排序
{
if(dcmp(a.angle-b.angle) == 0 ) return a.flag > b.flag ;
return a.angle < b.angle ;
}
double Sqrt(double x)
{
return x*x ;
}
double dist(const point &a,const point &b)
{
return sqrt(Sqrt(a.x-b.x)+Sqrt(a.y-b.y)) ;
} int main()
{
while(~scanf("%d %lf",&n,&r))
{
if(n == 0) break ;
for(int i = 0 ; i < n ; i++)
scanf("%lf %lf",&p[i].x,&p[i].y) ;
int ans = 0 ;
for(int i = 0 ; i < n ; i++)
{
int m = 0 ;
for(int j = 0 ; j < n ; j++)
{
if(i == j) continue ;
double d = dist(p[i],p[j]) ;
if(d > 2*r+0.001) continue ;
double s = atan2(p[j].y-p[i].y,p[j].x-p[i].x) ;
if(s < 0) s += 2*PI ;//角度区间修正
double ph = acos(d/2.0/r) ;//圆心角转区间 q[m++].angle = s - ph + 2*PI ;q[m-1].flag = 1 ;
q[m++].angle = s + ph + 2*PI ;q[m-1].flag = -1 ;
}
sort(q,q+m,cmp) ;
int sum = 0 ;
for(int j = 0 ; j < m ; j++)
{
ans = max(ans,sum += q[j].flag) ; }
}
printf("It is possible to cover %d points.\n",ans+1) ;
}
return 0 ;
}

最新文章

  1. ORACLE SQL前端补0的三种方式。
  2. Ubuntu Firefox installs Flashplayer
  3. Java Dao模式通过JDBC连接数据库的操作
  4. 暑假集训(3)第四弹 -----Frogger(Poj2253)
  5. position: absolute 的元素自动对齐父元素 border 外边缘
  6. SPOJ 416 - Divisibility by 15(贪心)
  7. 利用dedecms给近三天(或当天)发布的文章显示红色日期或加上new字或new小图片
  8. bespoke_百度百科
  9. sublime 2中Package control安装和使用
  10. 协同过滤(CF)算法
  11. 使用javaconfig配置freemarker
  12. 4天精通arcgis
  13. Beta冲刺 4
  14. 暴力解2018刑侦题python版
  15. Hibernate_HQL
  16. 接口app 接口中上传 图片
  17. Asp.Net Grieview Eval 绑定数据 调用JS事件
  18. [转]Java 变量和常量
  19. Chrome 调用vue.js 记录
  20. Django url反向解析与路由分发名称空间

热门文章

  1. hdu 5335 Walk Out (2015 Multi-University Training Contest 4)
  2. 深入分析JavaWeb Item39 -- 监听器(Listener)学习进阶
  3. Java 后台性能优化简要
  4. Spring整合TimerTask实现定时任务调度
  5. poj--1985--Cow Marathon(树的直径)
  6. [POJ 1316] 树上的询问
  7. Redis学习笔记(八) 基本命令:SortedSet操作
  8. httpclient定时请求实例
  9. [转]java多线程并发去调用一个类的静态方法安全性探讨
  10. VSCode新建vue文件自定义模板