HDU 2295 Radar (DLX + 二分)
Radar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2882 Accepted Submission(s): 1113
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
3 3 2
3 4
3 1
5 4
1 1
2 2
3 3
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <algorithm>
- #include <cstdlib>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- struct Node
- {
- double x,y;
- };
- const int HEAD = ;
- const int SIZE = ;
- int N,M,K;
- double RADAR[SIZE][SIZE];
- Node CITY[SIZE];
- bool VIS[SIZE];
- int U[SIZE * SIZE],D[SIZE * SIZE],L[SIZE * SIZE],R[SIZE * SIZE],C[SIZE * SIZE],S[SIZE * SIZE];
- int comp(const void * a,const void * b);
- int h(void);
- void debug(int count);
- void ini(void);
- bool dancing(int);
- void remove(int);
- void resume(int);
- int main(void)
- {
- int t;
- double x,y;
- scanf("%d",&t);
- while(t --)
- {
- scanf("%d%d%d",&N,&M,&K);
- for(int i = ;i < N;i ++)
- scanf("%lf%lf",&CITY[i].x,&CITY[i].y);
- for(int i = ;i < M;i ++)
- {
- scanf("%lf%lf",&x,&y);
- for(int j = ;j < N;j ++)
- RADAR[i][j] = sqrt(pow(CITY[j].x - x,) + pow(CITY[j].y - y,));
- }
- double l = ,r = ;
- double mid = ;
- while(r - l > 1e-)
- {
- mid = (l + r) / ;
- ini();
- int count = N + ;
- for(int i = ;i < M;i ++)
- {
- int first = count;
- for(int j = ;j < N;j ++)
- if(RADAR[i][j] <= mid)
- {
- R[count] = count + ;
- L[count] = count - ;
- U[count] = U[j + ];
- D[count] = j + ;
- D[U[j + ]] = count;
- U[j + ] = count;
- C[count] = j + ;
- S[j + ] ++;
- count ++;
- }
- L[first] = count - ;
- if(first != count)
- R[count - ] = first;
- }
- //debug(count );
- if(dancing())
- r = mid;
- else
- l = mid;
- }
- printf("%lf\n",mid);
- }
- return ;
- }
- void ini(void)
- {
- R[HEAD] = ;
- L[HEAD] = N;
- for(int i = ;i <= N;i ++)
- {
- L[i] = i - ;
- R[i] = i + ;
- U[i] = D[i] = C[i] = i;
- S[i] = ;
- }
- R[N] = HEAD;
- }
- bool dancing(int k)
- {
- if(R[HEAD] == HEAD)
- return true;
- if(k + h() > K)
- return false;
- int c = R[HEAD];
- for(int i = R[HEAD];i != HEAD;i = R[i])
- if(S[c] > S[i])
- c = i;
- for(int i = D[c];i != c;i = D[i])
- {
- remove(i);
- for(int j = R[i];j != i;j = R[j])
- remove(j);
- if(dancing(k + ))
- return true;
- for(int j = L[i];j != i;j = L[j])
- resume(j);
- resume(i);
- }
- return false;
- }
- void remove(int c)
- {
- for(int i = D[c];i != c;i = D[i])
- {
- L[R[i]] = L[i];
- R[L[i]] = R[i];
- }
- }
- void resume(int c)
- {
- for(int i = D[c];i != c;i = D[i])
- {
- L[R[i]] = i;
- R[L[i]] = i;
- }
- }
- void debug(int count)
- {
- for(int i = ;i < count;i ++)
- 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]);
- cout << endl << endl;
- }
- int h(void)
- {
- fill(VIS,VIS + SIZE,false);
- int count = ;
- for(int i = R[HEAD];i;i = R[i])
- if(!VIS[i])
- {
- count ++;
- VIS[i] = true;
- for(int j = D[i];j != i;j = D[j])
- for(int k = R[j];k != j;k = R[k])
- VIS[C[k]] = true;
- }
- return count;
- }
HDU 2295 Radar (DLX + 二分)的更多相关文章
- HDU 2295 Radar (二分 + Dancing Links 重复覆盖模型 )
以下转自 这里 : 最小支配集问题:二分枚举最小距离,判断可行性.可行性即重复覆盖模型,DLX解之. A*的启发函数: 对当前矩阵来说,选择一个未被控制的列,很明显该列最少需要1个行来控制,所以ans ...
- HDU 2295.Radar (DLX重复覆盖)
2分答案+DLX判断可行 不使用的估计函数的可重复覆盖的搜索树将十分庞大 #include <iostream> #include <cstring> #include < ...
- [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 ...
- 搜索(DLX重复覆盖模板):HDU 2295 Radar
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 2295 Radar 重复覆盖+二分
题目链接 给m个雷达, n个城市, 以及每个城市的坐标, m个雷达里只能使用k个, 在k个雷达包围所有城市的前提下, 求最小半径. 先求出每个雷达到所有城市的距离, 然后二分半径, 如果距离小于二分的 ...
- HDU 2295 Radar 重复覆盖 DLX
题意: N个城市,M个雷达站,K个操作员,问雷达的半径至少为多大,才能覆盖所有城市.M个雷达中最多只能有K个同时工作. 思路: 二分雷达的半径,看每个雷达可以覆盖哪些城市,然后做重复覆盖,判断这个半径 ...
- HDU 2295 Radar (重复覆盖)
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2295 Radar dancing links 重复覆盖
就是dancing links 求最小支配集,重复覆盖 精确覆盖时:每次缓存数据的时候,既删除行又删除列(这里的删除列,只是删除表头) 重复覆盖的时候:只删除列,因为可以重复覆盖 然后重复覆盖有一个估 ...
- 【HDOJ】2295 Radar
DLX+二分. /* 2295 */ #include <iostream> #include <string> #include <map> #include & ...
随机推荐
- Spark的应用程序
Spark的应用程序,分为两部分:Spark driver 和 Spark executor.
- Spark Streaming 原理剖析
通过源码呈现 Spark Streaming 的底层机制. 1. 初始化与接收数据 Spark Streaming 通过分布在各个节点上的接收器,缓存接收到的流数据,并将流数 据 包 装 成 Spar ...
- New full duplex HTTP tunnel implementation (client and server)
https://issues.jboss.org/browse/NETTY-246?page=com.atlassian.jirafisheyeplugin:fisheye-issuepanel —— ...
- UVALive 7327 Digit Division (模拟)
Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...
- POJ 2253 Frogger (dijkstra 最大边最小)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...
- Enterprise Library 中加密数据库连接字符串
看了SHY520写的关于Data Access Application Block的文章,写得不错,忽略了一点就是如何去加密数据库连接字符串,这儿我简单的介绍一下.我们知道,在Enterprise L ...
- Python beautifulsoup模块
BeautifulSoup中文文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ BeautifulSoup下载:http://w ...
- CGContext绘图
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContex ...
- linux常用命令-搜索
1.find $ find . -name nginx* $ find . -name nginx* -ls $ find . -type f -mmin -10 搜索当前目录中,所有过去10分钟中更 ...
- ios开发——仿新版iBooks书本打开与关闭动画
IOS新版iBooks吸引人的地方除了有干净整洁的界面.方便灵活的操作以及大容量的书籍容量以外.还有其优秀的用户交互,尤其是其动画的使用.打开一本书时书本缓慢放大并打开.关闭一本书后书本关闭并回到原位 ...