记录编号 20980 评测结果 AAAAAAAAAA
题目名称 漂亮字串 最终得分 100
用户昵称 Gravatardonny 是否通过 通过
代码语言 Pascal 运行时间 0.023 s
提交时间 2010-11-02 09:08:21 内存使用 0.11 MiB
显示代码纯文本
program bs;
var
  i,j,k,l:longint;
  x,xx,o,oo:longint;
  s,ss,m,mm:longint;
function suan(x,y:longint):longint;
var
  i:longint;
begin
  i:=x mod y;
  if i=0 then exit(x div y)
  else exit((x div y)+1);
end;
function min(x,y:longint):longint;
begin
  if x>y then exit(y)
  else exit(x);
end;
procedure find;
var
  i,j,k:longint;
begin
  if ((ss<=m)and(s>=m))or((ss<=mm)and(s>=m))or((mm>=ss)and(m<=s))or((mm<=s)and(m>=s)) then
    writeln(x+o)
    else
    begin
      if ss>m then
      begin
        writeln(o+min(x,(m+1)*xx));
      end
      else
      begin
        writeln(x+min((s+1)*oo,o));
      end;
    end;
end;
begin
  assign(input,'bs.in');
  reset(input);
  assign(output,'bs.out');
  rewrite(output);
  while not eof do
  begin
    readln(x,o,xx,oo);
    if x=0 then
    begin
      writeln(min(o,oo));
    end
    else
    if o=0 then
    begin
      writeln(min(x,xx));
    end
    else
    if xx=0 then
    begin
      writeln(min(o,oo));
    end
    else
    if oo=0 then
    begin
      writeln(min(x,xx));
    end
    else
    begin
    s:=x;
    ss:=suan(x,xx);
    m:=o;
    mm:=suan(o,oo);
    find;
    end;
  end;
  close(input);
  close(output);
end.