uvaLive 3415 Pascal
难得一个P党做uva
1 var n,k,i,x,y,ans,m,j,sp,sq,Hz:longint; 2 a:array[1..500,1..500] of boolean; 3 b:array[1..500] of longint; 4 c:array[1..500] of boolean; 5 tall,q,p:array[1..500]of longint; 6 sex:array[1..500]of boolean; 7 music,sport:array[1..500]of string; 8 st:string; 9 function path(x:longint):boolean; 10 var 11 i:longint; 12 begin 13 for i:=1 to n do 14 if a[x,i] and not c[i] then 15 begin 16 c[i]:=true; 17 if (b[i]=0) or path(b[i]) then 18 begin 19 b[i]:=x; 20 exit(true); 21 end; 22 end; 23 exit(false); 24 end; 25 begin 26 readln(Hz); 27 for Hz:=1 to Hz do 28 begin 29 readln(n); 30 sp:=0;sq:=0; 31 for i:=1 to n do 32 begin 33 readln(st); 34 tall[i]:=0; 35 for j:=1 to length(st)do 36 if(st[j]=' ')then break 37 else 38 tall[i]:=tall[i]*10+ord(st[j])-48; 39 sex[i]:=st[j+1]='M'; 40 if sex[i] then 41 begin 42 sp:=sp+1; 43 p[i]:=sp; 44 end 45 else 46 begin 47 sq:=sq+1; 48 q[i]:=sq; 49 end; 50 music[i]:=''; 51 for j:=j+3 to length(st)do 52 if(st[j]=' ')then break 53 else 54 music[i]:=music[i]+st[j]; 55 sport[i]:=''; 56 for j:=j+1 to length(st)do 57 if(st[j]=' ')then break 58 else 59 sport[i]:=sport[i]+st[j]; 60 end; 61 fillchar(a,sizeof(a),false); 62 for i:=1 to n do 63 for j:=1 to n do 64 if(i<>j)then 65 if sex[i] then 66 if(sex[i] xor sex[j])and(abs(tall[i]-tall[j])<=40)and(music[i]=music[j])and(sport[i]<>sport[j])then 67 a[p[i],q[j]]:=true; 68 m:=sp;n:=sq; 69 ans:=0; 70 fillchar(b,sizeof(b),0); 71 for i:=1 to m do 72 begin 73 fillchar(c,sizeof(c),false); 74 if path(i) then ans:=ans+1; 75 end; 76 writeln(m+n-ans); 77 end; 78 end.
错了很多遍
1.身高差≤40就可以,少打了等号
2.输入错掉☆害我白错5、6次,其他都是浮云
思路网上已经很详细了,这里主要给P党提供代码
匈牙利=>最大匹配=>最小点覆盖=反一下=>最大独立集
除了输入很烦以外,还是很裸的。

浙公网安备 33010602011771号