欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 狠狠色老熟妇老熟女 | 欧美色呦呦 | 精品久久一区二区三区 | 午夜理论电影在线观看亚洲 | 黑人精品| 两女互慰磨豆腐视频在线观看 | 男女在线观看啪网站 | 日韩欧美黄色片 | 日韩欧美在线免费观看 | 蜜桃视频在线播放 | 中文字幕视频在线 | 日本一本久草 | 日韩精品久久久久久久电影 | 日本高清午夜色wwwσ | 亚洲在线播放 | 一区二区在线看 | 97在线观看视频 | 欧美日韩一区二区不卡 | 国产毛A片啊久久久久久A | 欧美午夜视频一区二区三区 | 欧美成人在线免费观看 | 黄页网站免费高清在线观看 | 亚洲国产综合精品 | 国产一区久久久 | 婷婷色香五月激情综合2020 | 国产精品中文在线 | 高清国产一区二区三区四区五区 | 狠狠的撸2015最新版狠狠的撸2015最新版 | 亚洲精品午夜在线观看 | www.91p| 女人一级毛片免费视频观看 | 播五月开心婷婷综合 | 夜夜夜久久久 | 成人在线视频免费观看 | 欧美男女网站 | 欧洲视频在线观看 | 99精品视频3 | 孕妇体内谢精满日本电影 | 一级欧美视频 | 久久青草精品免费资源站 | 日日操夜夜爽 |