POJ 1328-Radar Installation(区间问题)_类似《照亮的山景》问题

POJ 1328 http://poj.org/problem?id=1328

 1 #include <cstdio>
 2 #include <cmath>
 3 
 4 struct unit {
 5     double h;
 6     double t;
 7     bool able;
 8 };
 9 
10 void work(int id,int m, int n);
11 bool get_ht(int r,int x,int y,double *ph,double *pt);
12 int main() {
13     int m, n;
14     int id=0;
15     scanf("%d %d", &m, &n);
16     while (!((m == 0) && (n == 0))) {
17         work(id++,m, n);
18         scanf("%d %d", &m, &n);
19     }
20     return 1;
21 }
22 void work(int id,int m, int n) {
23     //init
24     int x,y;
25     unit arr[1000];
26     int p = 0;
27     bool flag = true;
28     for (int i = 0; i < m; i++) {
29         scanf("%d %d", &x, &y);
30         if(!get_ht(n,x,y,&(arr[i].h),&(arr[i].t)))
31             flag = false;
32         arr[p++].able = true;
33     }
34     if(!flag){
35         printf("Case %d: -1\n",id+1);
36         return;
37     }
38     //sort
39     int len = p;
40     for (int i = 0; i < len; i++) {
41         for (int j = i + 1; j < len; j++) {
42             if (arr[i].h > arr[j].h) {
43                 unit temp = arr[i];
44                 arr[i] = arr[j];
45                 arr[j] = temp;
46             }
47         }
48     }
49     //disable the useless one
50     int tail = arr[len - 1].t;
51     for (int i = len - 2; i >= 0; i--) {
52         if (arr[i].t >= tail) {
53             arr[i].able = false;
54         } else {
55             tail = arr[i].t;
56         }
57     }
58     //find the radar
59     int count = 0;
60     double last = -5000000000;
61     for (int i = 0; i < len; i++) {
62         if ((arr[i].able) && (arr[i].h > last)) {
63             count++;
64             last = arr[i].t;
65         }
66     }
67     printf("Case %d: %d\n",id+1,count);
68 }
69 
70 bool get_ht(int r,int x,int y,double *ph,double *pt){
71     if((r<0)||(r*r-y*y<0)) return false;
72     double dlt = sqrt((r*r-y*y)*1.0);
73     *ph = x-dlt;
74     *pt = x+dlt;
75     return true;
76 }

CEOI 2000 Day 2 Problem 3---Enlightened landscape

Enlightened landscape

Consider a landscape composed of connected line segments:

Above the landscape, N light bulbs are hang at the same height T in various horizontal positions. The purpose of these light bulbs is to light up the entire landscape. A landscape point is considered lit if it can "see" a light bulb directly, that is, if the line segment which links the point with a bulb does not contain any other landscape segments point.

Task

Write a program that determines the mi-ni-mum number of light bulbs that must be switched on in order to illuminate the entire landscape.

Input

Input file name: LIGHT.IN
Line 1: M

  • An integer, the number of landscape height specifications, including the first and the last point of the landscape. 
    Lines 2..M+1: Xi Hi
  • Two integers, separated by a space: the landscape height Hi at horizontal position Xi, 1 <= i <= M; for 1 <= i <= M-1 we have Xi+1 > Xi; any two consecutive specified points identify a segment of line in the landscape. 
    Line M+2: N T
  • Two integers, separated by a space, the num-ber of light bulbs and their height coordinate (altitude). The bulbs are numbered from 1 to N) 
    Line M+3: B1 B2 ... BN
  • N integers, separated by spaces: the hori-zon-tal coordinates of the light bulbs Bi+1 > Bi, 1 ?i ?N-1;

    Output

    File name: LIGHT.OUT 
    Line 1: K
  • An integer: the minimum number of light bulbs to be switched on. 
    Line 2: L1 L2 ... LK
  • K integers, separated by spaces: the labels of the light bulbs to be switched on spe-cified in increasing order of their horizontal coordinates.

    Limits

  • 1 <= M <= 200
  • 1 <= N <= 200
  • 1 <= Xi <= 10000 for 1 <= i <= M
  • 1 < T <= 10000
  • 1 <= Hi <= 10000 for 1 <= i <= M
  • T > Hi for any 1 <= i <= M
  • X1 <= B1 and BN <=XM
  • The task always has a solution for the test data. If there are multiple solutions, only one is required.

    Sample Input

    6
    1 1
    3 3
    4 1
    7 1
    8 3
    11 1
    4 5
    1 5 6 10
    

    Sample Output

    2
    1 4
posted @ 2012-10-23 19:10  菜鸟程序员的奋斗&  阅读(544)  评论(0编辑  收藏  举报