欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 国产人成午夜免视频网站 | 免费看的久久久久 | 97超精品视频在线观看 | 国产成人高清 | 精品一区二区三区自拍图片区 | 精品国产不卡一区二区三区 | av一二三区 | 午夜在线视频一区二区三区 | 国产成人99 | 精品麻豆cm视频在线看 | 日本不卡一区二区 | 高清视频在线播放 | 9久9久女女免费精品视频在线观看 | 午夜久草| 中文字幕网在线 | 91香蕉国产视频 | 久久精品美女 | 范丞丞星座 | japanese嫩21videos | 黄在线观看在线播放720p | 波多野结衣中文在线播放 | 久久国产精品免费一区二区三区 | 久综合网 | 日日麻批的全部过程 | 日本中文字幕一区二区有码在线 | 色婷婷精品综合久久狠狠 | 亚洲第一男人天堂 | 狠狠干伊人 | yeyelu| 美女扒开胸罩给男生看视频 | 精品一区二区三区网站 | 亚洲国产区 | 97超碰免费 | 五月天色婷婷综合 | 国产福利在线播放 | 欧美性猛交一区二区三区精品 | 91亚洲国产成人久久精品网站 | 国产高清一国产免费软件 | 日本不卡一区在线 | 久久aⅴ乱码一区二区三区 日韩精品一区二区在线观看 | 午夜国产亚洲精品一区 |