1821: [JSOI2010]Group 部落划分 Group
1821: [JSOI2010]Group 部落划分 Group
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1308 Solved: 627
[Submit][Status]
Description
Input
Output
Sample Input
0 0
0 1
1 1
1 0
Sample Output
HINT
Source
题解:萌萌哒最小生成树不解释(呵呵呵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 var 11 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 begin 18 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 begin 24 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 begin 30 exit(getfat(x)=getfat(y)); 31 end; 32 procedure swap(var x,y:longint);inline; 33 var z:longint; 34 begin 35 z:=x;x:=y;y:=z; 36 end; 37 procedure sort(l,r:longint); 38 var i,j:longint;x,y:extended; 39 begin 40 i:=l;j:=r;x:=b[(l+r) div 2]; 41 repeat 42 while b[i]<x do inc(i); 43 while b[j]>x do dec(j); 44 if i<=j then 45 begin 46 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 begin 59 readln(n,m); 60 for i:=1 to n do 61 readln(d[i,1],d[i,2]); 62 k:=0; 63 for i:=1 to n-1 do 64 for j:=i+1 to n do 65 begin 66 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 do 76 begin 77 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.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。