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 |
枚举wa。。。无解输出什么?算法就是先从小到大排序,再直接枚举目标状态的每一个位置上的牌,然后判可行,找到第一个就退出,然后输出。。。怎么会wa呢,就是有多余空格也没事啊,难道是样例里给的输出格式不对? 如果是无解应该输出什么? ------------------------ 代码(有点长,我习惯敲回车键。。。) ------------------------ type tcard=record sign:char; num:longint; end; var i,j,k,l,m:longint; find:boolean; ans:longint; card:array[1..5] of tcard; res:array[1..5] of longint; n:longint; ch:char; p:longint; t:tcard; function smaller(c1,c2:tcard):boolean; begin if c1.num<c2.num then begin exit(true); end; if (c1.num=c2.num) and (c1.sign<c2.sign) then begin exit(true); end; exit(false); end; begin readln(n); for p:=1 to n do begin find:=false; ch:=' '; for j:=1 to 5 do begin while ch=' ' do begin read(ch); end; if ch<>'1' then begin if (ch>='2') and (ch<='9') then begin card[j].num:=ord(ch)-48; end else if ch='A' then begin card[j].num:=1; end else if ch='J' then begin card[j].num:=11; end else if ch='Q' then begin card[j].num:=12; end else if ch='K' then begin card[j].num:=13; end; end else begin card[j].num:=10; read(ch); end; read(ch); card[j].sign:=ch; read(ch); end; readln; for i:=1 to 5 do begin for j:=i+1 to 5 do begin if not smaller(card[i],card[j]) then begin t:=card[i]; card[i]:=card[j]; card[j]:=t; end; end; end; for i:=1 to 5 do begin for j:=1 to 5 do begin if (card[j].sign=card[i].sign) and (i<>j) then begin for k:=1 to 5 do begin if (i<>k) and (j<>k) then begin for l:=1 to 5 do begin if (i<>l) and (j<>l) and (k<>l) then begin for m:=1 to 5 do begin if (i<>m) and (j<>m) and (k<>m) and (l<>m) then begin ans:=1; if smaller(card[l],card[k]) and smaller(card[l],card[m]) then begin ans:=2; end; if smaller(card[m],card[k]) and smaller(card[m],card[l]) then begin ans:=3; end; if not smaller(card[k],card[l]) then begin ans:=ans+3; end; ans:=ans+card[j].num; if (ans-card[i].num) mod 13=0 then begin find:=true; break; end; end; end; if find then begin break; end; end; if find then begin break; end; end; if find then begin break; end; end; if find then begin break; end; end; if find then begin break; end; end; if find then begin break; end; end; if find then begin break; end; end; res[1]:=i; res[2]:=j; res[3]:=k; res[4]:=l; res[5]:=m; write('Problem ',p,':'); for j:=1 to 5 do begin write(' '); if (card[res[j]].num>=2) and (card[res[j]].num<=10) then begin write(card[res[j]].num); end else if card[res[j]].num=1 then begin write('A'); end else if card[res[j]].num=11 then begin write('J'); end else if card[res[j]].num=12 then begin write('Q'); end else if card[res[j]].num=13 then begin write('K'); end; write(card[res[j]].sign); end; writeln; end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator