Radar

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

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
 
 
 
 
昨天用G++交T了一下午,刚才换C++交了一发报RE了,发现是数组开小了,改后重交就过了,早知道是RE昨天就不会那么头疼了,再也不信G++。
用二分来找答案,城市作为列,每个雷达最为行,行和列的组合就是此雷达能否覆盖这个城市,每次给出一个二分数值后构造一个矩阵,然后dancing一下,如果能得到答案那么将值减小再尝试,反之加大。
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cstdlib>
  6. #include <cmath>
  7. #include <cstdio>
  8. using namespace std;
  9.  
  10. struct Node
  11. {
  12. double x,y;
  13. };
  14.  
  15. const int HEAD = ;
  16. const int SIZE = ;
  17. int N,M,K;
  18. double RADAR[SIZE][SIZE];
  19. Node CITY[SIZE];
  20. bool VIS[SIZE];
  21. int U[SIZE * SIZE],D[SIZE * SIZE],L[SIZE * SIZE],R[SIZE * SIZE],C[SIZE * SIZE],S[SIZE * SIZE];
  22.  
  23. int comp(const void * a,const void * b);
  24. int h(void);
  25. void debug(int count);
  26. void ini(void);
  27. bool dancing(int);
  28. void remove(int);
  29. void resume(int);
  30.  
  31. int main(void)
  32. {
  33. int t;
  34. double x,y;
  35.  
  36. scanf("%d",&t);
  37. while(t --)
  38. {
  39. scanf("%d%d%d",&N,&M,&K);
  40. for(int i = ;i < N;i ++)
  41. scanf("%lf%lf",&CITY[i].x,&CITY[i].y);
  42. for(int i = ;i < M;i ++)
  43. {
  44. scanf("%lf%lf",&x,&y);
  45. for(int j = ;j < N;j ++)
  46. RADAR[i][j] = sqrt(pow(CITY[j].x - x,) + pow(CITY[j].y - y,));
  47. }
  48.  
  49. double l = ,r = ;
  50. double mid = ;
  51. while(r - l > 1e-)
  52. {
  53. mid = (l + r) / ;
  54. ini();
  55.  
  56. int count = N + ;
  57. for(int i = ;i < M;i ++)
  58. {
  59. int first = count;
  60. for(int j = ;j < N;j ++)
  61. if(RADAR[i][j] <= mid)
  62. {
  63. R[count] = count + ;
  64. L[count] = count - ;
  65. U[count] = U[j + ];
  66. D[count] = j + ;
  67.  
  68. D[U[j + ]] = count;
  69. U[j + ] = count;
  70.  
  71. C[count] = j + ;
  72. S[j + ] ++;
  73. count ++;
  74. }
  75. L[first] = count - ;
  76. if(first != count)
  77. R[count - ] = first;
  78. }
  79. //debug(count );
  80. if(dancing())
  81. r = mid;
  82. else
  83. l = mid;
  84. }
  85.  
  86. printf("%lf\n",mid);
  87. }
  88.  
  89. return ;
  90. }
  91.  
  92. void ini(void)
  93. {
  94. R[HEAD] = ;
  95. L[HEAD] = N;
  96. for(int i = ;i <= N;i ++)
  97. {
  98. L[i] = i - ;
  99. R[i] = i + ;
  100. U[i] = D[i] = C[i] = i;
  101. S[i] = ;
  102. }
  103. R[N] = HEAD;
  104. }
  105.  
  106. bool dancing(int k)
  107. {
  108. if(R[HEAD] == HEAD)
  109. return true;
  110. if(k + h() > K)
  111. return false;
  112.  
  113. int c = R[HEAD];
  114. for(int i = R[HEAD];i != HEAD;i = R[i])
  115. if(S[c] > S[i])
  116. c = i;
  117.  
  118. for(int i = D[c];i != c;i = D[i])
  119. {
  120. remove(i);
  121. for(int j = R[i];j != i;j = R[j])
  122. remove(j);
  123. if(dancing(k + ))
  124. return true;
  125. for(int j = L[i];j != i;j = L[j])
  126. resume(j);
  127. resume(i);
  128. }
  129.  
  130. return false;
  131. }
  132.  
  133. void remove(int c)
  134. {
  135. for(int i = D[c];i != c;i = D[i])
  136. {
  137. L[R[i]] = L[i];
  138. R[L[i]] = R[i];
  139. }
  140. }
  141.  
  142. void resume(int c)
  143. {
  144. for(int i = D[c];i != c;i = D[i])
  145. {
  146. L[R[i]] = i;
  147. R[L[i]] = i;
  148. }
  149. }
  150.  
  151. void debug(int count)
  152. {
  153. for(int i = ;i < count;i ++)
  154. printf("%d U:%d D:%d L:%d R:%d C:%d S:%d\n",i,U[i],D[i],L[i],R[i],C[i],S[i]);
  155. cout << endl << endl;
  156. }
  157.  
  158. int h(void)
  159. {
  160. fill(VIS,VIS + SIZE,false);
  161.  
  162. int count = ;
  163. for(int i = R[HEAD];i;i = R[i])
  164. if(!VIS[i])
  165. {
  166. count ++;
  167. VIS[i] = true;
  168. for(int j = D[i];j != i;j = D[j])
  169. for(int k = R[j];k != j;k = R[k])
  170. VIS[C[k]] = true;
  171. }
  172. return count;
  173. }

HDU 2295 Radar (DLX + 二分)的更多相关文章

  1. HDU 2295 Radar (二分 + Dancing Links 重复覆盖模型 )

    以下转自 这里 : 最小支配集问题:二分枚举最小距离,判断可行性.可行性即重复覆盖模型,DLX解之. A*的启发函数: 对当前矩阵来说,选择一个未被控制的列,很明显该列最少需要1个行来控制,所以ans ...

  2. HDU 2295.Radar (DLX重复覆盖)

    2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...

  3. [ACM] HDU 2295 Radar (二分法+DLX 重复覆盖)

    Radar Problem Description N cities of the Java Kingdom need to be covered by radars for being in a s ...

  4. 搜索(DLX重复覆盖模板):HDU 2295 Radar

    Radar Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. hdu 2295 Radar 重复覆盖+二分

    题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...

  6. HDU 2295 Radar 重复覆盖 DLX

    题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...

  7. HDU 2295 Radar (重复覆盖)

    Radar Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. HDU 2295 Radar dancing links 重复覆盖

    就是dancing links 求最小支配集,重复覆盖 精确覆盖时:每次缓存数据的时候,既删除行又删除列(这里的删除列,只是删除表头) 重复覆盖的时候:只删除列,因为可以重复覆盖 然后重复覆盖有一个估 ...

  9. 【HDOJ】2295 Radar

    DLX+二分. /* 2295 */ #include <iostream> #include <string> #include <map> #include & ...

随机推荐

  1. Spark的应用程序

    Spark的应用程序,分为两部分:Spark driver 和 Spark executor.

  2. Spark Streaming 原理剖析

    通过源码呈现 Spark Streaming 的底层机制. 1. 初始化与接收数据 Spark Streaming 通过分布在各个节点上的接收器,缓存接收到的流数据,并将流数 据 包 装 成 Spar ...

  3. New full duplex HTTP tunnel implementation (client and server)

    https://issues.jboss.org/browse/NETTY-246?page=com.atlassian.jirafisheyeplugin:fisheye-issuepanel —— ...

  4. UVALive 7327 Digit Division (模拟)

    Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...

  5. POJ 2253 Frogger (dijkstra 最大边最小)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...

  6. Enterprise Library 中加密数据库连接字符串

    看了SHY520写的关于Data Access Application Block的文章,写得不错,忽略了一点就是如何去加密数据库连接字符串,这儿我简单的介绍一下.我们知道,在Enterprise L ...

  7. Python beautifulsoup模块

    BeautifulSoup中文文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ BeautifulSoup下载:http://w ...

  8. CGContext绘图

    0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContex ...

  9. linux常用命令-搜索

    1.find $ find . -name nginx* $ find . -name nginx* -ls $ find . -type f -mmin -10 搜索当前目录中,所有过去10分钟中更 ...

  10. ios开发——仿新版iBooks书本打开与关闭动画

    IOS新版iBooks吸引人的地方除了有干净整洁的界面.方便灵活的操作以及大容量的书籍容量以外.还有其优秀的用户交互,尤其是其动画的使用.打开一本书时书本缓慢放大并打开.关闭一本书后书本关闭并回到原位 ...