欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

poj 1328 Radar Installation (簡單的貪心)

系統 1837 0
Radar Installation
Time Limit: 1000MS ? Memory Limit: 10000K
Total Submissions: 42925 ? Accepted: 9485

Description

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.

We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.
poj 1328 Radar Installation (簡單的貪心)
Figure A Sample Input of Radar Installations


Input

The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.

The input is terminated by a line containing pair of zeros

Output

For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.

Sample Input

    3 2

1 2

-3 1

2 1



1 2

0 2



0 0


  

Sample Output

    Case 1: 2

Case 2: 1


  

Source

Beijing 2002

題目鏈接: http://poj.org/problem?id=1328

題意:有一條直的海岸線,上面有雷達。以海岸線為x軸,x軸上面為海,下面為岸。海里面有很多島嶼。已知雷達的觀測半徑。問最少建多少個雷達能把所有島嶼都覆蓋到雷達

?????????? 的偵測范圍內。如果不能覆蓋全部的島嶼,按樣例輸出Case數和-1,反之輸出Case數和最少需要建立的雷達數。

分析:首先算出經過每個雷達且平行于x軸的弦:假設雷達覆蓋半徑為d。則弦的左端點為x-sqrt (d*d-y*y),右端點為x+sqrt(d*d-y*y)。然后按左端點從小到大排序。由于不能受右

?????????? 端點的影響,將弦的左右端點橫坐標用結構體存起來。然后,將第一個雷達放在排序后的弦投影在x軸的右端點temp。從過第2個島嶼的弦的投影開始掃描,如果右端點

?????????? <temp即右端點在雷達左邊。把雷達移動到此右端點,此時就能使雷達既覆蓋到這個島嶼,又覆蓋到前面的島嶼。如果左端點在雷達右邊,則不能覆蓋,需要再建立一個

??????????? 雷達。然后把新雷達建在此時弦右端點投影到x軸的坐標。忽略前面的,對后面的島嶼進行同樣的操作。(貪心思想)

注意:半徑和坐標都有可能是小數,所以用double類型比較好,不然用int又要注意計算時*1.000變為浮點數。

代碼:

    #include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#include<cmath>

using namespace std;



struct point

{

    double left;

    double right;

}p[5012];

bool flag;

int cnt;



bool cmp(point &x,point &y)

{

    return x.left<y.left;

}



int main()

{

    int cases=0,i,n;

    double d;

    while(scanf("%d%lf",&n,&d)&&n&&d)

    {

        flag=true;

        double a,b;

        for(i=0;i<n;i++)

        {

            scanf("%lf%lf",&a,&b);

            if(fabs(b)>d)

	    flag=false;

            p[i].left=a-sqrt(d*d-b*b);

            p[i].right=a+sqrt(d*d-b*b);

        }

	printf("Case %d: ",++cases);

	if(!flag)

	    puts("-1");

	else

	{

	    sort(p,p+n,cmp);

	    double temp=p[0].right;

	    cnt=1;

	    for(i=1;i<n;i++)

	    {

		if(p[i].right<temp)

		   temp=p[i].right;

		else if(p[i].left>temp)

	        {

		   cnt++;

		   temp=p[i].right;

		}

	    } 

	    printf("%d\n",cnt);

	}

    }

    return 0;

}





//AC
  

?

?

?

11920732

fukan

1328

Accepted

188K

32MS

C++

981B

2013-08-05 00:20:15

?

?

?

poj 1328 Radar Installation (簡單的貪心)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久精品国产精品青草图片 | 日韩大片在线 | 九九热久久免费视频 | 欧美伦理一区 | 欧美影院久久 | 奇米影视7777久久精品人人爽 | 波多野结衣xfplay在线观看 | 欧美vide| 日韩在线精品 | 日本高清视频不卡 | 亚洲国产精品一区二区第一页 | 国产精品福利视频手机免费观看 | 久久亚洲精品国产精品黑人 | 国产换爱交换乱理伦片 | 2022国产成人福利精品视频 | 亚洲乱人伦在线 | 狠狠色噜噜狠狠狠狠色吗综合 | 欧美一级二级三级 | 久久久国产视频 | 二区国产 | 国产精品久久久久无码av | 欧美久久久无码精品亚洲日韩小说 | 经典香港一级a毛片免费看 亚洲精品国产精品国自产观看 | 日本成日本片人免费 | 日韩第3页 | 中文字幕三区 | 国产精品爽爽va在线观看网站 | 色呦呦在线看 | 三级网站免费观看 | 亚洲精品国产综合一线久久 | 我不卡在线 | 日本欧美久久久久免费播放网 | 日韩亚洲视频 | 99国产精品久久久久久久成人热 | 9191精品国产免费不久久 | 国产成人免费视频网站高清观看视频 | 日韩不卡免费视频 | 欧美精品久久久久久久免费观看 | www.日韩在线 | 精品一区二区三区水蜜桃 | 97天堂|