Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
pascalconst max=500; var v:array[0..max] of boolean; map:array[0..max,0..max] of boolean; match,height:array[0..max] of longint; music,sport:array[0..max] of string[20]; n,boys,t,i,j,k,a,b,h,save:longint; str:string[40]; ch:char; function dfs(p,b:longint):boolean; var i:longint; begin for i:=b to n do begin if (map[p,i]) and not v[i] then begin v[i]:=true; if (match[i]=-1) or dfs(match[i],b) then begin match[i]:=p; exit(true); end; end; end; exit(false); end; function compare(b,g:longint):boolean; begin if (height[b]-height[g]>40) or (height[g]-height[b]>40) then exit(false); if music[b]<>music[g] then exit(false); if sport[b]=sport[g] then exit(false); exit(true); end; begin //assign(input,'decency.in'); reset(input); //assign(output,'decency.out'); rewrite(output); readln(t); for j:=1 to t do begin readln(n); fillchar(map,sizeof(map),false); a:=0; b:=n+1; for i:=1 to n do begin read(h,ch,ch); if ch='M' then begin inc(a);k:=a; end else begin dec(b);k:=b; end; height[k]:=h; readln(ch,str); h:=pos(' ',str); music[k]:=copy(str,1,h-1); sport[k]:=copy(str,h+1,length(str)); end; boys:=a; for i:=1 to boys do for k:=boys+1 to n do if compare(i,k)=true then begin map[i,k]:=true; map[k,i]:=true; end; Save:=0; fillchar(match,sizeof(match),255); for i:=1 to boys do begin fillchar(v,sizeof(v),false); if dfs(i,b) then inc(save); end; writeln(n-Save); end; //close(input); close(output); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator