比赛 20101101 评测结果 WWWWWWWTTW
题目名称 漂亮字串 最终得分 0
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-01 19:53:15
显示代码纯文本
program bs;
var
        i,j,maxo,maxx,cx,co,ans:longint;
        st:ansistring;
procedure init;
begin
        assign(input,'bs.in');
        reset(input);
        assign(output,'bs.out');
        rewrite(output);
end;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure swap(var a,b:longint);
var
        t:longint;
begin
    t:=a;
    a:=b;
    b:=t;
end;
function ls(ss:ansistring):longint;
var
        i,s:longint;
        ch:char;
begin
    s:=0;
    ch:=ss[length(ss)];
    for i:=length(ss) downto 1 do
     if ss[i]<>ch then
      break else
       begin
           inc(s);
       end;
    exit(s);
end;
procedure main2;
var
        t,m1,m2:longint;
begin
        st:='';
        m1:=maxx;m2:=maxo;
        while m1>0 do
         begin
             dec(m1);
             st:=st+'X';
         end;
        while m2>0 do
         begin
             dec(m2);
             st:=st+'O';
         end;
        ans:=length(st);
        co:=co-maxo;
        cx:=cx-maxx;
        if co>cx then t:=cx else t:=co;
        dec(co,t);
        dec(cx,t);
        ans:=ans+t*2;
        if co=0 then
        begin
         if cx<=maxx then
         begin
             ans:=ans+cx;
             exit;
         end;
         if cx>maxx then
          begin
              ans:=ans+maxx;
              exit;
          end;
        end;//co=0
        if cx=0 then
         begin
          if co+ls(st)<=maxo then
           begin
               ans:=ans+co;
               exit;
           end;
          if co+ls(st)>maxo then
           begin
                ans:=ans+maxo-ls(st);
                exit;
           end;
         end;//cx=0
end;
procedure main;
var
        max,c1,c2:longint;
begin
        if (maxo=0)and(co<>0) then
         begin
             writeln(0);
             exit;
         end;
        if (maxx=0)and(cx<>0)then
         begin
             writeln(0);
             exit;
         end;
        if (cx<maxx)then
         begin
             writeln(0);
             exit;
         end;
        if (co<maxo)then
         begin
             writeln(0);
             exit;
         end;
         c1:=co;
         c2:=cx;
         main2;
         co:=c1;cx:=c2;
         max:=ans;
         swap(cx,co);
         swap(maxx,maxo);
         main2;
         if ans<max then ans:=max;
         writeln(ans);
end;
begin
        init;
        while not eoln do
        begin
        readln(co,cx,maxo,maxx);
        main;
        end;
        closef;
end.