【二分+最大团】【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 ...
随机推荐
- poj 2115 C Looooops(推公式+扩展欧几里得模板)
Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; ...
- poj 3301 Texas Trip(几何+三分)
Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in ...
- IOS Application生命周期
第一阶段 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *) ...
- 兼容各个浏览器的H.264播放: H.264+HTML5+FLOWPLAYER+WOWZA+RMTP
一.方案确定 计划做视频播放,要求可以播放H264编码的mp4文件,各个浏览器,各种终端都能播放. 首先查找可行性方案, http://www.cnblogs.com/sink_cup/archive ...
- Android应用程序窗口(Activity)的测量(Measure)、布局(Layout)和绘制(Draw)过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8372924 在前面一篇文章中,我们分析了And ...
- python3 module中__init__.py的需要注意的地方
网上关于__init__.py的作用的资料到处都是,我在此就不再啰嗦哪些了. 若有需要.请各位看官去搜搜即可. 最近刚开始用Python3 就遇到了这个比较有意思的事情 闲言少叙,下面要介绍的是pyt ...
- C语言的面向对象设计 —— 对 X264/FFMPEG 架构探讨
1.为什么要用C语言 直到今天,C语言虽然不是使用人数最多的语言了,但是C没有老去,在很多的核心系统代码里,依然跑的是设计精美的C,绝大多数的嵌入式开发核心库软件是C开发的,多数标准算法是基于标准C设 ...
- NPOI兼容 excel2003,2007版本
根据项目需要,需要对excel进行导入导出,所以选择NPOI,优点在这里就不详细介绍了,下面进入正题. public int Import(string path) { IList<Studen ...
- C#事件、委托简单示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Android sample 之模拟重力感应,加速度
class SimulationView extends View implements SensorEventListener { // diameter of the balls in meter ...