麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

poj 1328 區間,貪心

2019-11-11 07:24:48
字體:
來源:轉載
供稿:網友

        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.
Figure A Sample Input of Radar Installations
InputThe 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 OutputFor 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 21 2-3 12 11 20 20 0Sample Output
Case 1: 2Case 2: 1

給定海島個數、雷達半徑以及各海島坐標,求能覆蓋所有海島的最小雷達數。

貪心策略依然是從左往右,盡量讓每顆雷達覆蓋最大島嶼數。

對于每個點先求出以該點為圓心,d為半徑的圓在x軸上的交點,左右交點就是覆蓋此海島的雷達所在的區間。

對于每個區間,按照區間的右端點排序。

從最左邊開始貪心,對于第一個右端點x0,所有左端點<x0的海島都會與x0共用一個雷達

#include<iostream>#include<cmath>#include<cstring>#include<cstdio>#include<algorithm>#define inf 0x3f3f3f3f#define ll long longusing namespace std;struct node{    int x,y;}q[1010];struct xnode{    double l,r;}xn[1010];bool cmp(xnode a,xnode b){    if(a.r==b.r)        return a.l<b.l;    return a.r<b.r;}bool visited[1010];int main(){    int n,d;    int kcase=1;    while(cin>>n>>d)    {        if(n==0)            return 0;        bool flag=0;        for(int i=1;i<=n;i++)        {            cin>>q[i].x>>q[i].y;            if(q[i].y>d)                flag=1;        }        if(flag==1||d==0)        {            cout<<"Case "<<kcase++<<": "<<-1<<endl;            continue;        }        for(int i=1;i<=n;i++)        {            double len=sqrt(1.0*d*d-q[i].y*q[i].y);            xn[i].l=q[i].x-len;            xn[i].r=q[i].x+len;        }        sort(xn+1,xn+n+1,cmp);        int ans=0;        memset(visited,0,sizeof(visited));        for(int i=1;i<=n;i++)            if(!visited[i])        {            visited[i]=1;            ans++;            for(int j=i+1;j<=n;j++)                if(!visited[j]&&xn[j].l<=xn[i].r)                    visited[j]=1;        }         cout<<"Case "<<kcase++<<": "<<ans<<endl;    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人在线视频免费 | 久久精品re | 妇子乱av一区二区三区 | 国产精品自拍99 | 日本免费aaa观看 | 黄色大片在线免费看 | 国产成人精品免费视频大全办公室 | 久久老司机精品视频 | 午夜视频导航 | 九九热在线精品视频 | 视频毛片| 欧美一级做一级爱a做片性 久久久资源网 | 韩国一大片a毛片 | 亚洲小视频在线 | 天天躁狠狠躁夜躁2020挡不住 | 日韩午夜片 | 国产精品视频久久久 | 一级α片 | 孕妇体内谢精满日本电影 | 亚洲成人在线视频网站 | 国产精品视频1区 | 欧美一级特黄aaaaaa在线看首页 | 最近日本电影hd免费观看 | 一级毛片在线观看免费 | 一区二区三区日韩 | 久久亚洲成人 | 九九热在线精品视频 | 成人福利视频在 | 欧美aⅴ在线观看 | 黄色av免费网站 | 国产一区二区三区四区五区精品 | 国产精品成人av片免费看最爱 | 日本爽快片100色毛片视频 | 精品一区二区三区毛片 | 中国videos露脸hd | 免费看成年人网站 | 国产成人av免费观看 | 成人福利视频在 | 国产精品久久久久久久久久iiiii | 欧洲成人精品 | 模特三级在线观看 |