当前位置: 代码迷 >> 综合 >> 【2012.03.3普及组】打牌
  详细解决方案

【2012.03.3普及组】打牌

热度:24   发布时间:2023-10-09 12:33:29.0
 有A、B两个玩家玩打牌游戏:

●一共有2N张牌,每张牌上数字不同,从1到2N.(1<=N<=100);

●每个玩家有N张牌;

●每个玩家按照以下规则轮流出牌也可能不出:

ⅰ:第一个玩家先打出一张牌;

ⅱ:每次玩家出的牌必须比另一个玩家刚刚出的牌要大;

ⅲ:如果有牌可以出就一定要出;

ⅳ:如果玩家没有牌可以出就不出,这种情况下由刚才的玩家继续出牌;

●当某个玩家手上没牌时游戏结束;

●每个玩家获得的分数为对手剩下的牌数;

●最重要的一点是每个玩家必须在可出的牌中找一个最小的来出!

A先出牌,写一个程序计算A,B两个人的得分。


题解:

  模拟,来一波程序————————

代码

typearr=array[0..200] of longint;
vars,s1:arr;t:array[1..300] of boolean;n:longint;
procedure px;
vari,j,t:longint;
beginfor i:=1 to n-1 dofor j:=i+1 to n doif s[i]>s[j] thenbegint:=s[i];s[i]:=s[j];s[j]:=t;end;
end;
procedure init;
varm,i,j:longint;
beginfillchar(t,sizeof(t),true);readln(n);j:=1;for i:=1 to n dobeginreadln(s[i]);t[s[i]]:=false;end;for i:=1 to 2*n doif t[i] thenbegins1[j]:=i;inc(j);end;px;
end;
vari,j,a,b:longint;temp,c:boolean;
begininit;temp:=true;s[0]:=n;s1[0]:=n;while (s[0]<>0)and(s1[0]<>0) dobeginc:=false;if temp thenbeginfor j:=1 to n doif s[j]>b thenbegina:=s[j];s[j]:=0;dec(s[0]);c:=true;break;end;if c=false thena:=0;temp:=false;endelsebeginfor j:=1 to n doif s1[j]>a thenbeginb:=s1[j];s1[j]:=0;dec(s1[0]);c:=true;break;end;if c=false thenb:=0;temp:=true;end;end;a:=0;b:=0;for i:=1 to n dobeginif s1[i]<>0 then inc(a);if s[i]<>0 then inc(b);end;writeln(a);writeln(b);
end.

  相关解决方案