集训队专题(5.1)1003 maximum shortest distance
来源:互联网 发布:沈阳医疗软件代理 编辑:程序博客网 时间:2024/06/01 09:11
maximum shortest distance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1386 Accepted Submission(s): 469
Problem Description
There are n points in the plane. Your task is to pick k points (k>=2), and make the closest points in these k points as far as possible.
Input
For each case, the first line contains two integers n and k. The following n lines represent n points. Each contains two integers x and y. 2<=n<=50, 2<=k<=n, 0<=x,y<10000.
Output
For each case, output a line contains a real number with precision up to two decimal places.
Sample Input
3 20 010 00 20
Sample Output
22.36
Author
alpc50
Source
2010 ACM-ICPC Multi-University Training Contest(15)——Host by NUDT
此题是一个最大团的变形问题,题目给出k,和n个点,求出n个点之间的距离,让你求出最小的lim,两点距离大于lim算连通,使得最大团的顶点数不小于k。距离方面可以用二分的思想来优化,而最大团直接套小编给出的最大团模板即可。
#include <math.h>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn=50+10;int g[maxn][maxn],dp[maxn],stk[maxn][maxn],mx;void dfs(int n, int ns, int dep){ if (ns == 0){ if (dep > mx) mx = dep; return ; } int i,j,k,p,cnt; for(i=0; i<ns; i++){k = stk[dep][i];cnt = 0;if(dep + n - k <= mx) return ;if(dep + dp[k] <= mx) return ;for(j=i+1; j<ns; j++){p = stk[dep][j];if(g[k][p]) stk[dep+1][cnt++] = p;}dfs(n, cnt, dep+1);} return ;}int clique(int n){int i,j,ns;for(mx=0, i=n-1; i>=0; i--){for(ns=0, j=i+1; j<n; j++)if(g[i][j]) stk[1][ns++] = j;dfs(n, ns, 1);dp[i] = mx;}return mx;}int x[maxn],y[maxn],n,k;double arc[maxn][maxn],dis[maxn*maxn];bool check(double lim){int i,j;memset(g,0,sizeof(g));for(int i=0; i<n; i++)for(int j=i+1; j<n; j++)if(arc[i][j] >= lim)g[i][j] = g[j][i] = 1;if(clique(n) >= k) return true;else return false;}int main(){int i,j,cnt;while(scanf("%d%d",&n,&k)!=EOF){for(i=0; i<n; i++) scanf("%d%d",&x[i],&y[i]);cnt=0;for(i=0; i<n; i++){arc[i][i] = -1;for(j=i+1; j<n; j++){arc[i][j] = sqrt((double)((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])));dis[cnt++] = arc[j][i] = arc[i][j];}}sort(dis,dis+cnt);int l=0,r=cnt-1,mid,ans;while(l<=r){mid = (l+r)>>1;if(check(dis[mid])){ans = mid;l = mid+1;}else r = mid-1;}printf("%.2lf\n",dis[ans]);}return 0;}
0 0
- 集训队专题(5.1)1003 maximum shortest distance
- 集训队专题(5.1)1001 Maximum Clique
- hdu3585 maximum shortest distance
- hdoj 3585 maximum shortest distance(二分+最大团)
- HDOJ 3585 maximum shortest distance (二分+最大团)
- HDOJ 2585 maximum shortest distance(求最大团+二分)
- 【二分+最大团】【HDU3585】【maximum shortest distance】
- 集训队专题(1)1003 Phone List
- 集训队专题(4)1003 Activation
- 集训队专题(7)1003 Task Schedule
- 集训队专题(9)1003 Frosh Week
- 集训队专题(5.1)1006 Channel Allocation
- 集训队专题(5.1)1007 All Friends
- 集训队专题(5.1)1008 Graph Coloring
- hdu 3585 maximum shortest distance 二分小技巧
- HDU 3585 Maximum Shortest Distance 最大团 二分答案
- HDU 3585 maximum shortest distance 二分+最大团
- 集训队专题(2)1003 Matrix Power Series
- switf元组
- Android强制横屏或竖屏注意事项
- HTTP协议详解
- Servlet引擎:Tomcat与Jetty比较
- 自定义PHP的错误报告处理方式
- 集训队专题(5.1)1003 maximum shortest distance
- Ubuntu 14.04LTS修改显示分辨率
- 【Boost】Interprocess - 共享内存、文件映射介绍
- 将TXT文件中的数据整理成sql数据库
- jenkins git can't work ERROR: Timeout after 10 minutes ERROR: Error fetching remote repo 'origin'
- Tomcat的生命周期管理
- 碰到的C语言的关于循环取数的方法
- Notifydatesetchanged的用法:
- BZOJ1008越狱