记录编号 48460 评测结果 AAAAAAAAAA
题目名称 漂亮字串 最终得分 100
用户昵称 Gravatardigital-T 是否通过 通过
代码语言 Pascal 运行时间 0.012 s
提交时间 2012-11-05 20:01:16 内存使用 0.17 MiB
显示代码纯文本
var
a,b,c,d,maxo,maxx,counto,countx,t:longint;
function maxfff(x,y:longint):longint;
begin
 if x>=y then maxfff:=x else maxfff:=y;
end;
begin
assign(input,'bs.in');reset(input);
assign(output,'bs.out');rewrite(output);
while not eof do
begin
 counto:=-1;
 read(counto,countx,maxo,maxx);
 if counto>-1 then

 begin
 a:=0;b:=0;c:=0;d:=0;
 if maxo>0 then begin a:=counto div maxo;c:=counto mod maxo;end;
 if maxx>0 then begin b:=countx div maxx;d:=countx mod maxx;end;
 if (counto>0)and(countx>0)and(maxo>0)and(maxx>0)then
  begin
   if a=b then if b=0 then write(counto+countx)
   else
    begin
     if(maxo=1)and(maxx=1)then write(a*maxo+b*maxx+maxfff(c,d));
     if(maxo>1)and(maxx=1)then write(a*counto+b*countx+c);
     if(maxo=1)and(maxx>1)then write(a*counto+b*countx+d);
     if(maxo>1)and(maxx>1)then write(counto+countx);
    end;
  //_________________________________________________________________
   if (a+1=b)or(b+1=a) then
    write(countx+counto);
  //_________________________________________________________________
   if a>b+1 then
    if maxx=1 then write(b*2+1)
     else
      begin
       if (countx>100000)or(counto>100000)then t:=0 else t:=(countx+1)*(maxo+1)-1;
       if t>=counto+countx then write(counto+countx);
       if (t<counto+countx)and(t>0)then write((countx+1)*(maxo+1)-1);
       if t=0 then write(counto+countx);
      end;
  //__________________________________________________________________
   if b>a+1 then
    if maxo=1 then write(a*2+1)
     else
      begin
       if (counto>100000)or(countx>100000)then t:=0 else t:=(counto+1)*(maxx+1)-1;
       if t>=counto+countx then write(counto+countx);
       if (t<counto+countx)and(t>0)then write((counto+1)*(maxx+1)-1);
       if t=0 then write(counto+countx);
      end;
   //__________________________________________________________________
  writeln;
  end;

 if (counto=0)and(countx=0)then writeln(0);
 if (counto>0)and(countx=0)then if counto>maxo then writeln(maxo)else writeln(counto);
 if (counto=0)and(countx>0)then if countx>maxx then writeln(maxx)else writeln(countx);

 if (counto>0)and(countx>0)and(maxo>0)and(maxx=0)then if counto>maxo then writeln(maxo)else writeln(counto);
 if (counto>0)and(countx>0)and(maxo=0)and(maxx>0)then if countx>maxx then writeln(maxx)else writeln(countx);
 if (counto>0)and(countx>0)and(maxo=0)and(maxx=0)then writeln(0);
 readln;
 end;
end;
close(input);
close(output);
end.