模拟试——repair

来源:互联网 发布:vb页面跳转 编辑:程序博客网 时间:2024/05/21 02:35

题目大意:
在N个城市中选择M个来开维修店,求选择哪些城市开维修店可以使得离维修店最远的那个城市离维修店的距离尽量小。给出N个城市的坐标(城市的坐标是唯一的),求出这个最小的距离。

对于50%的数据,1 ≤ M ≤ N ≤ 10,-100 ≤ X,Y ≤ 100;
对于所有的数据,1 ≤ M ≤ N ≤ 20,-1000 ≤ X,Y ≤ 1000。

题解:
根据数据我们不然发现裸搜即可。
先用勾股定理计算2点之间距离,然后每一次搜索,如果当前在该城市修维修站对结果有影响,就在当前城市修一个。
然后每次修完M个以后就判断一下当前中的最大值。
然后拿最大值跟答案对比找个最小值。

var      a:Array [0..21,0..21] of real;      x,y,mix:array [0..21] of real;      i,j,n,m,max:longint;      pq,ans:real;procedure dfs(dep,num:longint);var      p,q:array [0..21] of real;      i,j:longint;      k:boolean;begin      if num+(n-dep+1)<m then exit;      if num=m then      begin           pq:=0;           for i:=1 to n do             if mix[i]>pq then pq:=mix[i];           if ans>pq then ans:=pq;      end;      for i:=dep to n do      begin           k:=false;           p:=mix;           for j:=1 to n do               if mix[j]>a[i,j] then               begin                     mix[j]:=a[i,j];                     k:=true;               end;           if k then           begin                 dfs(i+1,num+1);                 mix:=p;           end;      end;end;begin      assign(input,'repair.in'); reset(input);      assign(output,'repair.out'); rewrite(output);      readln(n,m);      for i:=1 to n do readln(x[i],y[i]);      for i:=1 to n do        for j:=1 to n do          a[i,j]:=sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j]));      for i:=1 to n do mix[i]:=5000;      ans:=5000;      dfs(1,0);      writeln(ans:0:2);      close(input); close(output);end.