• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            oyjpArt ACM/ICPC算法程序設(shè)計空間

            // I am new in programming, welcome to my blog
            I am oyjpart(alpc12, 四城)
            posts - 224, comments - 694, trackbacks - 0, articles - 6

            PKU 1328 Radar Installation

            Posted on 2007-06-22 20:00 oyjpart 閱讀(2992) 評論(0)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽

            Radar Installation
            Time Limit:1000MS  Memory Limit:10000K
            Total Submit:2704 Accepted:564

            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.


            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


            Algorithm: Greedy
            Step 1: 輸入數(shù)據(jù) 如果有一個點的y坐標(biāo)大于d 直接輸出-1 長生相應(yīng)的區(qū)間(在某一個區(qū)間里任意放置一個Radar 則是這個Island可視)
            Step 2: 按照左端點排序(如果左端點相等 則必須按右邊反向排序, 理由在于下一步為了篩選出包含的 必須的把大范圍的放到前面) 注意這里面最好要用浮點判斷規(guī)則
            Step 3: 利用Stack對這些區(qū)間做預(yù)處理 把被包含的區(qū)間標(biāo)識出來
            Step 4: 貪心選擇右端的點

            #include <stdio.h>
            #include <string.h>
            #include <algorithm>
            #include <math.h>
            using namespace std;

            const int N = 1000;
            const double EPS = 1e-7;

            struct E { double a, b; } e[N];
            int n, d;
            bool ava[N];
            double p[N];

            inline int dblcmp(double a, double b) {
             if( fabs(a-b) < EPS ) return 0;
             if( a-b > 0 ) return 1;
             return -1;
            }

            bool operator<(const E& a, const E& b) {
             if(dblcmp(a.a, b.a) == 0)
              return dblcmp(a.b, b.b) == 1;
             return dblcmp(a.a, b.a) == -1;
            }


            int main() {
             int i, j, x, y;
             int tc = 0;
             while(scanf("%d %d", &n, &d), n + d) {
              tc++;
              int ok = 1;
              for(i = 0; i < n; ++i) {
               scanf("%d %d", &x, &y);
               if(y > d) ok = 0;
               double offset = sqrt ( d * d - y * y );
               e[i].a = x - offset, e[i].b = x + offset;
               ava[i] = 1;
              }
              if(!ok) { printf("Case %d: -1\n", tc); continue; }
              sort(e, e + n);
              int stack[N], top = 0;
              stack[top++] = 0;
              for(i = 1; i < n; ++i) {
               while(top > 0 && dblcmp(e[stack[top-1]].b, e[i].b) != -1)  {
                ava[stack[--top]] = 0;
               }
               stack[top++] = i;
              }
              
              for(i = 0; !ava[i]; ++i);
              p[i] = e[i].b;
              int cnt = 1;
              for(i = i+1; i < n; ++i) if(ava[i]) {
               for(j = i-1; !ava[j]; j--);
               if(p[j] >= e[i].a)  p[i] = p[j];
               else { p[i] = e[i].b; cnt++; }
              }
              printf("Case %d: %d\n", tc, cnt);
             }
             return 0;
            }

            久久精品国产一区二区三区不卡 | 亚洲国产天堂久久久久久| 狠狠色丁香婷婷久久综合不卡| 亚洲国产另类久久久精品黑人| 久久91精品国产91久久麻豆| 久久精品一区二区三区中文字幕| 亚洲国产综合久久天堂| MM131亚洲国产美女久久| 国产成人精品久久综合| 亚洲精品乱码久久久久久| 欧美久久综合性欧美| 三级三级久久三级久久| 一本色道久久88加勒比—综合| 亚洲美日韩Av中文字幕无码久久久妻妇 | 久久受www免费人成_看片中文| 一本久道久久综合狠狠躁AV| 久久精品国产久精国产| 久久无码国产专区精品| 国产成人精品综合久久久| 无码精品久久久天天影视| 久久精品亚洲福利| 免费观看久久精彩视频| 青青草原精品99久久精品66| 亚洲综合久久久| 久久久久久国产a免费观看不卡| 久久精品亚洲一区二区三区浴池| 性欧美大战久久久久久久| 国产精品女同一区二区久久| 97r久久精品国产99国产精| 人妻少妇久久中文字幕一区二区| 久久久久国色AV免费观看| 久久青青草原国产精品免费 | 精品一久久香蕉国产线看播放| 亚洲精品乱码久久久久66| 久久无码AV中文出轨人妻| 久久久久国产成人精品亚洲午夜| 亚洲国产精品久久久久| 国产成人久久777777| 久久久久久A亚洲欧洲AV冫| 亚洲国产成人久久一区WWW| 性高朝久久久久久久久久|