哈理工2015暑假訓練賽 zoj 2078Phone Cell,zoj2078phone

來源:互聯網
上載者:User

哈理工2015暑假訓練賽 zoj 2078Phone Cell,zoj2078phone
Phone CellTime Limit:10000MS    Memory Limit:32768KB    64bit IO Format:%lld & %lluSubmitStatusPracticeZOJ 2978

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 distanceR, 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 numbersN 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 areN 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 pointsS 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.", whereM is the maximal number of points of interest that may be covered by a single BTS.

Sample Input

8 21 25 35 41 48 24 57 53 32 1000 1000 -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 ;}



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.