HDU 2295 Radar
来源:互联网 发布:室内设计师 知乎 编辑:程序博客网 时间:2024/06/04 19:34
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
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
13 3 23 43 15 41 12 23 3
Sample Output
2.236068二分+dlx重复覆盖验证
#include<cstdio>#include<vector>#include<cmath>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const ll maxn = 1005;int n, m, x[maxn], y[maxn], T, k;inline void read(int &ret){ char c; do { c = getchar(); } while (c < '0' || c > '9'); ret = c - '0'; while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');}struct DLX{ #define maxn 10005 #define F(i,A,s) for (int i=A[s];i!=s;i=A[i]) int L[maxn], R[maxn], U[maxn], D[maxn]; int row[maxn], col[maxn], ans[maxn], cnt[maxn]; int n, m, num, sz; bool Flag; void add(int now, int l, int r, int u, int d, int x, int y) { L[now] = l; R[now] = r; U[now] = u; D[now] = d; row[now] = x; col[now] = y; } void reset(int n, int m) { Flag = false; this->n = n; this->m = m; for (int i = 0; i <= m; i++) { add(i, i - 1, i + 1, i, i, 0, i); cnt[i] = 0; } L[0] = m; R[m] = 0; sz = m + 1; } void insert(int x, int y) { int ft = sz - 1; if (row[ft] != x) { add(sz, sz, sz, U[y], y, x, y); U[D[sz]] = sz; D[U[sz]] = sz; } else { add(sz, ft, R[ft], U[y], y, x, y); R[L[sz]] = sz; L[R[sz]] = sz; U[D[sz]] = sz; D[U[sz]] = sz; } ++cnt[y]; ++sz; } //精确覆盖 void remove(int now) { R[L[now]] = R[now]; L[R[now]] = L[now]; F(i,D,now) F(j,R,i) { D[U[j]] = D[j]; U[D[j]] = U[j]; --cnt[col[j]]; } } void resume(int now) { F(i,U,now) F(j,L,i) { D[U[j]] = j; U[D[j]] = j; ++cnt[col[j]]; } R[L[now]] = now; L[R[now]] = now; } int dfs(int x) { if (!R[0]) return 1; int now = R[0]; F(i,R,0) if (cnt[now]>cnt[i]) now = i; remove(now); F(i,D,now) { ans[x] = row[i]; F(j,R,i) remove(col[j]); if (dfs(x + 1)) return 1; F(j,L,i) resume(col[j]); } resume(now); return 0; } //精确覆盖 //重复覆盖 void Remove(int now) { F(i,D,now) { L[R[i]]=L[i]; R[L[i]]=R[i]; } } void Resume(int now) { F(i,U,now) L[R[i]]=R[L[i]]=i; } int vis[maxn]; int flag[maxn]; int A() { int dis=0; F(i,R,0) vis[i]=0; F(i,R,0) if (!vis[i]) { dis++; vis[i]=1; F(j,D,i) F(k,R,j) vis[col[k]]=1; } return dis; } void Dfs(int x) { if (!R[0]) num=min(num,x); else if (x+A()<num) { int now=R[0]; F(i,R,0) if (cnt[now]>cnt[i]) now = i; F(i,D,now) { Remove(i);F(j,R,i) Remove(j); Dfs(x+1); F(j,L,i) Resume(j);Resume(i); } } } void mul() { num=0x7FFFFFFF; } //重复覆盖}dlx;void reset(double xx){ dlx.reset(m,n); for (int i=1;i<=m;++i) { for (int j=1;j<=n;++j) { double u=(x[n+i]-x[j])*(x[n+i]-x[j])+(y[n+i]-y[j])*(y[n+i]-y[j]); if (xx-sqrt(u)>1e-8) dlx.insert(i,j); } }}bool check(){ dlx.mul(); dlx.Dfs(0); if (dlx.num<=k) return true; else return false;}int main(){ read(T); while (T--) { scanf("%d%d%d",&n,&m,&k); for (int i=1;i<=n+m;++i) scanf("%d%d",&x[i],&y[i]); double l,r,mid; for (l=0,r=1500;r-l>1e-8;) { mid=(l+r)/2; reset(mid); if (check()) r=mid; else l=mid; } printf("%.6lf\n",r); } return 0;}
0 0
- HDU 2295 Radar
- hdu 2295 Radar
- HDU 2295 Radar DLX重复覆盖
- hdu 2295 Radar(重复覆盖,二分+DLX)
- 【HDU】2295 Radar 二分+重复覆盖
- HDU 2295 Radar(重复覆盖,DLX)
- HDU 2295 Radar (二分+DLX,重复覆盖)
- HDU 2295 Radar(二分+重复覆盖)
- hdu 2295 Radar(重复覆盖问题)
- HDU 2295 Radar(二分加DLX)
- HDU 2295 Radar DLX重复覆盖
- [HDU]2295 Radar 跳舞链 重复覆盖
- HDU 2295 Radar【二分+Dancing Links重复覆盖】
- HDU 2295 Radar( 二分+Dancing Links重复覆盖 )
- [ACM] HDU 2295 Radar (二分+DLX 重复覆盖)
- HDU 2295 Radar(DLX可重复覆盖)
- hdu 2295 Radar(Dancing Links重复覆盖)
- [ACM] HDU 2295 Radar (二分+DLX 重复覆盖)
- linux下部署多台tomcat
- hdu 2955 Robberies解题报告
- android实战中遇到的问题汇总
- 主席树初探
- 【MFC-7】VS2010编程之浏览文件夹
- HDU 2295 Radar
- SQLServer中事务日志已满的原因以及解决办法
- Ubuntu 下大文件夹分卷压缩
- IntelliJ IDEA 注册码
- Android蓝牙开发浅谈
- OS X下JAVA开发环境搭建
- JVM 进阶 六
- MYCNCART 自适应主题模板 MCCThemes-005
- 【Discuz】打开网站提示Oops! System file lost: class/class_mysqli.php无法进入论坛与输入密码错误多次被禁止尝试