zoukankan      html  css  js  c++  java
  • HDU 2295 Radar (重复覆盖)

    Radar

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2280    Accepted Submission(s): 897


    Problem Description
    N cities of the Java Kingdom need to be covered by radars for being in a state of war. Since the kingdom has M radar stations but only K operators, we can at most operate K radars. All radars have the same circular coverage with a radius of R. Our goal is to minimize R while covering the entire city with no more than K radars.
     
    Input
    The input consists of several test cases. The first line of the input consists of an integer T, indicating the number of test cases. The first line of each test case consists of 3 integers: N, M, K, representing the number of cities, the number of radar stations and the number of operators. Each of the following N lines consists of the coordinate of a city.
    Each of the last M lines consists of the coordinate of a radar station.

    All coordinates are separated by one space.
    Technical Specification

    1. 1 ≤ T ≤ 20
    2. 1 ≤ N, M ≤ 50
    3. 1 ≤ K ≤ M
    4. 0 ≤ X, Y ≤ 1000
     
    Output
    For each test case, output the radius on a single line, rounded to six fractional digits.
     
    Sample Input
    1 3 3 2 3 4 3 1 5 4 1 1 2 2 3 3
     
    Sample Output
    2.236068
     
    Source
     

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2295

    二分答案, 然后使用重复覆盖的Dancing Links模板进行判断,看使用K个能不能覆盖n个点

      1 /* ***********************************************
      2 Author        :kuangbin
      3 Created Time  :2014/5/26 22:20:05
      4 File Name     :E:2014ACM专题学习DLXHDU2295.cpp
      5 ************************************************ */
      6 
      7 #include <stdio.h>
      8 #include <string.h>
      9 #include <iostream>
     10 #include <algorithm>
     11 #include <vector>
     12 #include <queue>
     13 #include <set>
     14 #include <map>
     15 #include <string>
     16 #include <math.h>
     17 #include <stdlib.h>
     18 #include <time.h>
     19 using namespace std;
     20 const int maxnode = 3000;
     21 const int MaxM = 55;
     22 const int MaxN = 55;
     23 int K;
     24 struct DLX
     25 {
     26     int n,m,size;
     27     int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode];
     28     int H[MaxN],S[MaxN];
     29     int ands,ans[MaxN];
     30     void init(int _n,int _m)
     31     {
     32         n = _n;
     33         m = _m;
     34         for(int i = 0;i <= m;i++)
     35         {
     36             S[i] = 0;
     37             U[i] = D[i] = i;
     38             L[i] = i-1;
     39             R[i] = i+1;
     40         }
     41         R[m] = 0; L[0] = m;
     42         size = m;
     43         for(int i = 1;i <= n;i++)
     44             H[i] = -1;
     45     }
     46     void Link(int r,int c)
     47     {
     48         ++S[Col[++size]=c];
     49         Row[size] = r;
     50         D[size] = D[c];
     51         U[D[c]] = size;
     52         U[size] = c;
     53         D[c] = size;
     54         if(H[r] < 0)H[r] = L[size] = R[size] = size;
     55         else
     56         {
     57             R[size] = R[H[r]];
     58             L[R[H[r]]] = size;
     59             L[size] = H[r];
     60             R[H[r]] = size;
     61         }
     62     }
     63     void remove(int c)
     64     {
     65         for(int i = D[c];i != c;i = D[i])
     66             L[R[i]] = L[i], R[L[i]] = R[i];
     67     }
     68     void resume(int c)
     69     {
     70         for(int i = U[c];i != c;i = U[i])
     71             L[R[i]]=R[L[i]]=i;
     72     }
     73     bool v[maxnode];
     74     int f()
     75     {
     76         int ret = 0;
     77         for(int c = R[0];c != 0;c = R[c])v[c] = true;
     78         for(int c = R[0];c != 0;c = R[c])
     79             if(v[c])
     80             {
     81                 ret++;
     82                 v[c] = false;
     83                 for(int i = D[c];i != c;i = D[i])
     84                     for(int j = R[i];j != i;j = R[j])
     85                         v[Col[j]] = false;
     86             }
     87         return ret;
     88 
     89     }
     90     bool Dance(int d)
     91     {
     92         if(d + f() > K)return false;
     93         if(R[0] == 0)return d <= K;
     94         int c = R[0];
     95         for(int i = R[0];i != 0;i = R[i])
     96             if(S[i] < S[c])
     97                 c = i;
     98         for(int i = D[c];i != c;i = D[i])
     99         {
    100             remove(i);
    101             for(int j = R[i];j != i;j = R[j])remove(j);
    102             if(Dance(d+1))return true;
    103             for(int j = L[i];j != i;j = L[j])resume(j);
    104             resume(i);
    105         }
    106         return false;
    107     }
    108 };
    109 DLX g;
    110 const double eps = 1e-8;
    111 struct Point
    112 {
    113     int x,y;
    114     void input()
    115     {
    116         scanf("%d%d",&x,&y);
    117     }
    118 }city[MaxM],station[MaxN];
    119 double dis(Point a,Point b)
    120 {
    121     return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y));
    122 }
    123 
    124 int main()
    125 {
    126     //freopen("in.txt","r",stdin);
    127     //freopen("out.txt","w",stdout);
    128     int T;
    129     int n,m;
    130     scanf("%d",&T);
    131     while(T--)
    132     {
    133         scanf("%d%d%d",&n,&m,&K);
    134         for(int i = 0;i < n;i++)city[i].input();
    135         for(int i = 0;i < m;i++)station[i].input();
    136         double l = 0, r = 1e8;
    137         while(r-l >= eps)
    138         {
    139             double mid = (l+r)/2;
    140             g.init(m,n);
    141             for(int i = 0;i < m;i++)
    142                 for(int j = 0;j < n;j++)
    143                     if(dis(station[i],city[j]) < mid - eps)
    144                         g.Link(i+1,j+1);
    145             if(g.Dance(0))r = mid-eps;
    146             else l = mid+eps;
    147         }
    148         printf("%.6lf
    ",l);
    149     }
    150     return 0;
    151 }
  • 相关阅读:
    制作透明色:《CSS3 RGBA》与Opacity样式用法
    制作动画效果:《CSS3 Animation》
    CISCO运维记录之3650堆叠设备升级IOS(Version 16.3.6版本存在bug)
    08 Zabbix4.0系统配置事件通知
    24 Zabbix系统配置日志监控告警--关键字触发
    15 Zabbix Item类型之Zabbix trapper类型
    06 Zabbix4.0系统CISCO交换机告警模板规划信息(基础)
    05 Zabbix4.0触发器表达式Trigger expression支持的函数
    04 Zabbix4.0系统配置触发器trigger
    03 Zabbix4.0添加cisco交换机基本监控步骤
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3755557.html
Copyright © 2011-2022 走看看