【二分+最大团】【HDU3585】【maximum shortest distance】
题目大意
在N个点钟 选出K个点 使得这K个点间的最小距离最大
二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间
< K , 向下缩小区间
OK~
#include<stdio.h>
#include<math.h>
#include<iostream>
#define eps 1e-7
using namespace std; int n,k,vis[55],tmax,dp[55],ji;
int locat[55][2],map[55][55];
double dis[55][55],distan[2000]; int cmp(const void *a,const void*b)
{
return *(double *)a>*(double *)b?1:-1;
} void build(int mid)
{
int i,f;
for(i=1;i<=n;i++)
{
for(f=1;f<=n;f++)
{
if(dis[i][f] >= distan[mid]-eps)
{
map[i][f]=1;
}
else
{
map[i][f]=0;
}
}
map[i][i]=0;
}
} void dfs(int id,int cnt)
{
int tvis[55],i,f,able=0;
for(i=id+1;i<=n;i++)
{
if(1 == vis[i])
{
able++;
}
}
if(0 == able)
{
tmax=max(tmax,cnt);
}
if(cnt + able <= tmax)
{
return ;
}
for(i=1;i<=n;i++)
{
tvis[i]=vis[i];
}
for(i=id+1;i<=n;i++)
{
if(0 == tvis[i])
{
continue;
}
if(cnt +dp[i] <= tmax)
{
continue;
}
for(f=id+1;f<=n;f++)
{
vis[f]=tvis[f]&map[i][f];
}
dfs(i,cnt+1);
}
} int max_clique()
{
int i,f;
tmax=1;
dp[n]=1;
for(i=n-1;i>=1;i--)
{
for(f=1;f<=n;f++)
{
vis[f]=map[i][f];
}
dfs(i,1);
dp[i]=tmax;
if(n == tmax)
{
return tmax;
}
}
return tmax;
} double bs()
{
int l=0,r=ji,mid;
while(l != r-1)
{
mid=(l+r)>>1;
build(mid);
if(k <= max_clique())
{
l=mid;
}
else
{
r=mid;
}
}
return distan[l];
} int main()
{
int i,f,g,sum;
while(scanf("%d%d",&n,&k)!=EOF)
{
ji=0;
for(i=1;i<=n;i++)
{
scanf("%d%d",&locat[i][0],&locat[i][1]);
}
for(i=1;i<=n;i++)
{
for(f=1;f<=n;f++)
{
sum=0;
for(g=0;g<2;g++)
{
sum+=(locat[i][g]-locat[f][g])*((locat[i][g]-locat[f][g]));
}
dis[i][f]=sqrt((double)sum);
if(i > f)
{
distan[ji]=dis[i][f];
ji++;
}
}
}
qsort(distan,ji,sizeof(distan[0]),cmp);
printf("%.2lf\n",bs());
}
return 0;
}
【二分+最大团】【HDU3585】【maximum shortest distance】的更多相关文章
- maximum shortest distance
maximum shortest distance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- Maximum Shortest Distance 最大团 二分答案 HDU 3585
题意:给出n个点 要求取k个点 这k个点中 距离最小的两个点要求距离最大 拿到手看不出是最大团 也看不出是二分答案(第一次用) 因为答案必然存在 一定有一个最值 所以用二分答案来做 最大距 ...
- [LeetCode] Shortest Distance to a Character 到字符的最短距离
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- 【LeetCode】1182. Shortest Distance to Target Color 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+二分查找 日期 题目地址:https://lee ...
- [CareerCup] 18.5 Shortest Distance between Two Words 两单词间的最短距离
18.5 You have a large text file containing words. Given any two words, find the shortest distance (i ...
- [Locked] Shortest Distance from All Buildings
Shortest Distance from All Buildings You want to build a house on an empty land which reaches all bu ...
- PAT1046: Shortest Distance
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- [Swift]LeetCode821. 字符的最短距离 | Shortest Distance to a Character
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- LeetCode 613. Shortest Distance in a Line
Table point holds the x coordinate of some points on x-axis in a plane, which are all integers. Writ ...
随机推荐
- 遍历父视图上的button
for (UIView * thebtn in [self.view subviews]) { if ([thebtn isKindOfClass:[UIButton class]]) { //*** ...
- SQL With(递归 CTE 查询)
本文来自:http://www.cnblogs.com/smailxiaobai/archive/2012/01/16/2323291.html 指定临时命名的结果集,这些结果集称为公用表表达式 (C ...
- react redux 相关技术
React全都是围绕着组件的, 所以React基础也就是:写组件的jsx.组件的生命周期以及组件的属性和状态.jsx,只要是用过html模板的分分钟就能写了: 所谓生命周期就是组件在创建.销毁.更新阶 ...
- windows下sqlplus / as sysdba报ora-12560的解决方法
环境:win7_64位.数据库版本ORACLE11G_R2 在CMD窗口,使用下面三个命令可正常连接数据库:C:\Users\Administrator> sqplus /nolog C:\Us ...
- UVA 1212 Duopoly
题目: 两个公司进行投标,竞争一些channels,每个投标可以包含多个channels,且都有一定的收益,每一个channels只能为其中的一个公司利用,同时保证一个公司给出的投标中选中的chann ...
- Json.Net序列化和反序列化设置
首先补充一点,Json.Net是支持序列化和反序列化DataTable,DataSet,Entity Framework和NHibernate的.我举例说明DataTable的序列化和反序列化.创建一 ...
- php Debugging with Xdebug and Sublime Text 3(转)
Debugging – we all do it a lot. Writing code perfectly the first time around is hard and only a few ...
- hadoop源码编译
为何要自行编译hadoop源码,往往是由于官方提供的hadoop发行版都是基于32位操作系统,在操作hadoop时会发生warn. 准备软件: 1)JDK 2)Hadoop源码 3)Maven 4 ...
- UVA 12113 Overlapping Squares
题意: 总共有6个2*2的正方形,判断是否能够成所给的形状. 思路: 一个正方形总共有9种摆放方式,对于整个地图来说摆放方式总共有2的9次方种摆放方式.然后将地图用9*5的数组表示,正方形的位置用其8 ...
- 类与对象 - PHP手册笔记
基本概念 PHP对待对象的方式与引用和句柄相同,即每个变量都持有对象的引用,而不是整个对象的拷贝. 当创建新对象时,该对象总是被赋值,除非该对象定义了构造函数并且在出错时抛出了一个异常.类应在被实例化 ...