超时?

P1968 美元汇率

菜鸟让让我 @ 2016-06-19 21:03:44

var
  mei,ma:real;
  f:boolean;
  i,n:longint;
  a:array[1..110]of longint;
begin
  readln(n);
  for i:=1 to n do
    readln(a[i]);
  f:=true;
  mei:=100;
  ma:=0;
  i:=1;
  repeat
    if(f)and(a[i]>a[i+1])then
    begin
      f:=false;
      ma:=(mei/100)*a[i];
      mei:=0;
      inc(i);
    end
    else
    if(f)and(a[i]<a[i+1])then
      inc(i)
    else
    if(not(f))and(a[i]<a[i+1])then
    begin
      f:=true;
      mei:=(ma/a[i])*100;
      ma:=0;
      inc(i);
    end
    else
    if(not(f))and(a[i]>a[i+1])then
      inc(i);
  until(i=n);
  mei:=(ma/a[n])*100;
  writeln(mei:0:2);
end.
超时,神犇帮帮我

by zhych @ 2016-06-20 19:05:54

第几个数据超时


by zhych @ 2016-06-20 19:08:42

repeat循环有点粗劣。


|