题目:给出平面上n个点,现在找m个点,并且使得这m个点最近的两个最远。

分析:显然这满足二分的性质,二分答案,根据点距离需要大于等于二分值重新构造新图,则问题变成了:在新图中找出满足所有点对之间的距离大于等于二分的值的一个子图。因此在新图中寻找最大团即可。具体看代码

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue
#define cmax(x,y) x = max(x,y)
#define cmin(x,y) x = min(x,y)
#define Clear(x) memset(x,0,sizeof(x))
/* #pragma comment(linker, "/STACK:1024000000,1024000000") int size = 256 << 20; // 256MB
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p) ); */ char IN;
bool NEG;
inline void Int(int &x){
NEG = 0;
while(!isdigit(IN=getchar()))
if(IN=='-')NEG = 1;
x = IN-'0';
while(isdigit(IN=getchar()))
x = x*10+IN-'0';
if(NEG)x = -x;
}
inline void LL(ll &x){
NEG = 0;
while(!isdigit(IN=getchar()))
if(IN=='-')NEG = 1;
x = IN-'0';
while(isdigit(IN=getchar()))
x = x*10+IN-'0';
if(NEG)x = -x;
} /******** program ********************/ const int MAXN = 50; int g[MAXN][MAXN],n;
bool use[MAXN];
int dp[MAXN],best,m; int px[MAXN],py[MAXN];
double dis[MAXN][MAXN];
//int pre[MAXN],path[MAXN]; // 记录路径 bool dfs(int *id,int top,int cnt){
if(!top){
if(best<cnt){
//copy( pre+1,pre+cnt+1,path ); // 记录路径
best = cnt;
return true;
}
return false;
}
int a[MAXN];
rep(i,top){
if(cnt+top-i<=best)return false;
if(cnt+dp[id[i]]<=best)return false;
//pre[cnt] = id[i]; // 记录路径
int k = 0;
for(int j=i+1;j<top;j++)
if(g[id[i]][id[j]])
a[k++] = id[j];
if(dfs(a,k,cnt+1))return true;
}
return false;
} inline int solve(){
int id[MAXN];
best = 0;
for(int i=n-1;i>=0;i--){
int top = 0;
for(int j=i+1;j<n;j++)
if(g[i][j])
id[top++] = j;
dfs(id,top,1);
dp[i] = best;
}
return best;
} inline bool build(double mid){
Clear(g);
rep(i,n)
rep(j,n)
g[i][j] = dis[i][j]>=mid;
return solve()>=m;
} double cal(int x,int y){
return sqrt(x*x+y*y+0.0);
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif while(~RD2(n,m)){
rep(i,n)
RD2(px[i],py[i]);
rep(i,n)
for(int j=i+1;j<n;j++)
dis[i][j] = dis[j][i] = cal(px[i]-px[j],py[i]-py[j]);
double l = 0 , r = 10000000;
double ans = 0;
rep(step,50){
double mid = (l+r)/2;
if(build(mid)){
l = mid;
ans = mid;
}else r = mid;
}
printf("%.2lf\n",ans);
} return 0;
}

  

hdu 3585 二分+最大团的更多相关文章

  1. hdu 4024 二分

    转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html   一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...

  2. Maximum Shortest Distance 最大团 二分答案 HDU 3585

    题意:给出n个点   要求取k个点  这k个点中  距离最小的两个点要求距离最大 拿到手看不出是最大团  也看不出是二分答案(第一次用) 因为答案必然存在 一定有一个最值  所以用二分答案来做 最大距 ...

  3. hdu 1669(二分+多重匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 思路:由于要求minimize the size of the largest group,由此 ...

  4. 【二分+最大团】【HDU3585】【maximum shortest distance】

    题目大意 在N个点钟 选出K个点 使得这K个点间的最小距离最大 二分距离,然后如果两点间距离小于它的边当做不存在,求出最大团,如果最大团>=K,向上缩小区间 <  K  ,  向下缩小区间 ...

  5. HDU 3586 二分答案+树形DP判定

    HDU 3586 『Link』HDU 3586 『Type』二分答案+树形DP判定 ✡Problem: 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...

  6. hdu 4004 (二分加贪心) 青蛙过河

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...

  7. hdu 5046 二分+DLX模板

    http://acm.hdu.edu.cn/showproblem.php?pid=5046 n城市建k机场使得,是每个城市最近机场的距离的最大值最小化 二分+DLX 模板题 #include < ...

  8. HDU 5699 二分+线性约束

    http://acm.hdu.edu.cn/showproblem.php?pid=5699 此题满足二分性质,关键在于如何判断当前的时间值可以满足所有的运送方案中的最长的时间. 对于每一次枚举出的k ...

  9. hdu 3277(二分+最大流+拆点+离线处理+模板问题...)

    Marriage Match III Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. [转][IIS]发布网站,提示用户 'IIS APPPOOL\***' 登录失败。

    链接:http://www.cnblogs.com/tianguook/p/3881075.html 用户 'IIS APPPOOL\DefaultAppPool' 登录失败. 我在windows8中 ...

  2. js中的call及apply

    http://www.zhihu.com/question/20289071 func1.call(this, arg1, arg2); 或者 func1.apply(this, [arg1, arg ...

  3. C#高性能大容量SOCKET并发(一):IOCP完成端口例子介绍(转)

    原文地址 http://blog.csdn.net/SQLDebug_Fan/article/details/17556353 例子主要包括SocketAsyncEventArgs通讯封装.服务端实现 ...

  4. 计算Excel中的Sheet个数

    $strpath="d:\ee.xlsx"$excel=new-object -comobject excel.application$WorkBook = $excel.Work ...

  5. Python-面向对象 (二 继承)

    一 继承   基类定义例如以下: class people:     #define attribute     name = ''     age  = 0     #define private ...

  6. 【转】C++ 异常

    一.什么是异常处理 一句话:异常处理就是处理程序中的错误. 二.为什么需要异常处理,以及异常处理的基本思想 C++之父Bjarne Stroustrup在<The C++ Programming ...

  7. freemarker中的round、floor和ceiling数字的舍入处理

    freemarker中的round.floor和ceiling数字的舍入处理 1.简易说明 (1)round:四舍五入 (2)floor:向下取整 (3)ceiling:向上取整 2.举例说明 < ...

  8. linux脚本^M: bad interpreter:解决方法

    转自:http://blog.csdn.net/huiguixian/article/details/6386774 在Linux中执行.sh脚本,异常提示/bin/sh^M: bad interpr ...

  9. java.net.SocketException四大异常解决方案【转】

    java.net.SocketException如何才能更好的使用呢?这个就需要我们先要了解有关这个语言的相关问题.希望大家有所帮助.那么我们就来看看有关java.net.SocketExceptio ...

  10. Flex4+Spring3+Hibernate3+BlazeDS整合笔记

    普通Java Web工程流行使用ssh框架,而当前台使用Flex制作的时候,后台就不需要用Struts了,通过使用BlazeDS远程方法调用即可. 首先,新建Java Web工程,然后添加Flex项目 ...