比赛 20121106 评测结果 AWWWWWWWWWWWWWW
题目名称 二十一点 最终得分 6
用户昵称 bw 运行时间 0.007 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2012-11-06 10:47:04
显示代码纯文本
program ex;
  var f,data:array[0..1000] of longint;
  n,i,j,k,ans,biao,tt,sum1,sum2:longint;
   begin
    assign(input,'jack.in');
    assign(output,'jack.out');
    reset(input);
    rewrite(output);
     read(n);
      for i:=1 to n do
       read(data[i]);
       fillchar(f,sizeof(f),255);
       f[0]:=0;
      for i:=1 to n-5 do
         if f[i-1]<>-1 then
          for j:=0 to 21 do
          begin
          tt:=0;
           biao:=i+4;
           sum1:=data[i]+data[i+2];
           sum2:=data[i+1]+data[i+3];
           while (sum1<=16)or(j>tt) do
           begin
            if (sum1>21) or(sum2>21) then break;
            if sum1<=16 then
            begin
            sum1:=sum1+data[biao];  inc(biao); if biao>n then break; end;
            if tt<j then begin sum2:=sum2+data[biao];
            inc(tt); inc(biao); if biao>n then break; end;
           end;
           if (sum1>=sum2) and(sum1<=21) then f[i+biao-2]:=f[i-1]
           else f[i+biao-2]:=f[i-1]+1;
          end;
    for i:=n-4 to n do
       if f[i]>ans then ans:=f[i];
    write(ans);
    close(input); close(output);
    end.