hdu3585 maximum shortest distance
来源:互联网 发布:js 延迟1s 编辑:程序博客网 时间:2024/06/07 06:55
maximum shortest distance
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
题意:在N个点钟 选出K个点 使得这K个点间的最小距离最大
思路:二分答案+最大团
#include<bits/stdc++.h>using namespace std;#define Hash(a,b) (a-1)*n+bconst int maxn=51;double mp[maxn][maxn];int num[maxn],k;int G[maxn][maxn],ret;bool dfs(int *adj,int tot,int cnt){ if(cnt>=k){ ret=cnt; return 1; } if(tot==0){ if(cnt>ret){ ret=cnt; return 1; } return 0; } for(int i=0;i<tot;i++){ if(cnt+tot-i<=ret) continue; if(cnt+num[adj[i]]<=ret) continue; int t[maxn],k=0; for(int j=i+1;j<tot;j++){ if(G[adj[i]][adj[j]]) t[k ++] = adj[j]; } if(dfs(t,k,cnt+1)) return 1; } return 0;}void Maxclique(int n){ int adj[maxn],tot; for(int i=n;i>=1;i--){ tot=0; for(int j=i+1;j<=n;j++) if(G[i][j]==1) adj[tot++]=j; dfs(adj,tot,1); if(ret>=k) return ; num[i]=ret; }}struct Point{ double x,y;}node[maxn];double distance(int i,int j){ return sqrt((node[i].y-node[j].y)*(node[i].y-node[j].y)+(node[i].x-node[j].x)*(node[i].x-node[j].x));}int main(){ int _; int n; while(scanf("%d%d",&n,&k)!=EOF){ memset(G,0,sizeof(G)); ret=0; for(int i=1;i<=n;i++) scanf("%lf%lf",&node[i].x,&node[i].y); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) mp[i][j]=distance(i,j); double low=0,high=20000; while(high-low>=1e-4){ ret=0; double mid=(low+high)/2; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ if(mp[i][j]>=mid) G[i][j]=1; else G[i][j]=0; } Maxclique(n); if(ret>=k) low=mid+(1e-4); else high=mid-(1e-4); } printf("%.2f\n",(high+low)/2); } return 0;}
0 0
- hdu3585 maximum shortest distance
- 【二分+最大团】【HDU3585】【maximum shortest distance】
- hdu 3585 maximum shortest distance 二分小技巧
- HDU 3585 Maximum Shortest Distance 最大团 二分答案
- hdoj 3585 maximum shortest distance(二分+最大团)
- 集训队专题(5.1)1003 maximum shortest distance
- HDU 3585 maximum shortest distance 二分+最大团
- HDOJ 3585 maximum shortest distance (二分+最大团)
- HDOJ 2585 maximum shortest distance(求最大团+二分)
- HDU 3585 maximum shortest distance 最大团+简单的二分思想
- 1046. Shortest Distance
- pat 1046 Shortest Distance
- 1046. Shortest Distance (20)
- 1046. Shortest Distance
- 1046. Shortest Distance (20)
- 1046. Shortest Distance (20)
- 1046. Shortest Distance (20)
- 1046. Shortest Distance (20)
- spring(JDBC)事务配置
- Android 任务栈、Intent.FlAG_ACTIVITY_xxx、Activity四种启动模式
- SpringBoot定时任务说明
- 复杂可变数组的排序---(数组中存的是对象)---mutablearray
- Could not build module 'UIKit'问题
- hdu3585 maximum shortest distance
- mongodb学习笔记
- 自定义Dialog时,会遇到dialog wrap_content,这个时候需要手动设置Dialog大小
- 1、字符串的操作
- debian 发行代号
- ssh远程登陆命令
- WPF数据绑定学习
- 全面复习之SQL(8)-oracle存储过程
- Codeforces Round #246 (Div. 2)(B)数学