1821: [JSOI2010]Group 部落劃分 Group

來源:互聯網
上載者:User

標籤:

1821: [JSOI2010]Group 部落劃分 GroupTime Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1308  Solved: 627
[Submit][Status]
Description聰聰研究發現,荒島野人總是過著群居的生活,但是,並不是整個荒島上的所有野人都屬於同一個部落,野人們總是拉幫結派形成屬於自己的部落,不同的部落之間則經常發生爭鬥。只是,這一切都成為謎團了——聰聰根本就不知道部落究竟是如何分布的。 不過好訊息是,聰聰得到了一份荒島的地圖。地圖上標註了N個野人居住的地點(可以看作是平面上的座標)。我們知道,同一個部落的野人總是生活在附近。我們把兩個部落的距離,定義為部落中距離最近的那兩個居住點的距離。聰聰還獲得了一個有意義的資訊——這些野人總共被分為了K個部落!這真是個好訊息。聰聰希望從這些資訊裡挖掘出所有部落的詳細資料。他正在嘗試這樣一種演算法: 對於任意一種部落劃分的方法,都能夠求出兩個部落之間的距離,聰聰希望求出一種部落劃分的方法,使靠得最近的兩個部落儘可能遠離。 例如,下面的左圖表示了一個好的劃分,而右圖則不是。請你編程協助聰聰解決這個難題。Input第一行包含兩個整數N和K(1<=N<=1000,1<k<=n),分別代表了野人居住點的數量和部落的數量。 接下來n行,每行包含兩個正整數x,y,描述了一個居住點的座標(0<="x," y<="10000)。" <="" div="">Output輸出一行,為最優劃分時,最近的兩個部落的距離,精確到小數點後兩位。Sample Input4 2
0 0
0 1
1 1
1 0


Sample Output1.00

HINT Source

JSOI2010第二輪Contest1

 

題解:萌萌噠最小產生樹不解釋(呵呵呵JSOI居然也出現過這樣的題目)

 1 /************************************************************** 2     Problem: 1821 3     User: HansBug 4     Language: Pascal 5     Result: Accepted 6     Time:272 ms 7     Memory:25656 kb 8 ****************************************************************/ 9  10 var11    i,j,k,l,m,n,tt:longint;12    a,d:array[0..1000050,1..2] of longint;13  14    b:array[0..1000050] of extended;15    c:array[0..10050] of longint;16 function getfat(x:longint):longint;inline;17          begin18               if c[x]<>x then c[x]:=getfat(c[x]);19               getfat:=c[x];20          end;21 procedure merge(x,y:longint);inline;22           var a1,a2:longint;23           begin24                a1:=getfat(x);a2:=getfat(y);25                if a1=a2 then exit;26                dec(tt);c[a1]:=a2;27           end;28 function tog(x,y:longint):boolean;inline;29          begin30               exit(getfat(x)=getfat(y));31          end;32 procedure swap(var x,y:longint);inline;33           var z:longint;34           begin35                z:=x;x:=y;y:=z;36           end;37 procedure sort(l,r:longint);38           var i,j:longint;x,y:extended;39           begin40                i:=l;j:=r;x:=b[(l+r) div 2];41                repeat42                      while b[i]<x do inc(i);43                      while b[j]>x do dec(j);44                      if i<=j then45                         begin46                              y:=b[i];47                              b[i]:=b[j];48                              b[j]:=y;49                              swap(a[i,1],a[j,1]);50                              swap(a[i,2],a[j,2]);51                              inc(i);dec(j);52                         end;53                until i>j;54                if i<r then sort(i,r);55                if l<j then sort(l,j);56           end;57  58 begin59      readln(n,m);60      for i:=1 to n do61          readln(d[i,1],d[i,2]);62      k:=0;63      for i:=1 to n-1 do64          for j:=i+1 to n do65              begin66                   inc(k);67                   a[k,1]:=i;68                   a[k,2]:=j;69                   b[k]:=sqrt(sqr(d[i,1]-d[j,1])+sqr(d[i,2]-d[j,2]));70              end;71      tt:=n;72      for i:=1 to n do c[i]:=i;73      sort(1,k);74      i:=0;75      while tt>m do76            begin77                 inc(i);78                 while tog(a[i,1],a[i,2]) do inc(i);79                 merge(a[i,1],a[i,2]);80            end;81      inc(i);82      while tog(a[i,1],a[i,2]) do inc(i);83      writeln(b[i]:0:2);84 end.

 

1821: [JSOI2010]Group 部落劃分 Group

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.