比赛 NOIP_2 评测结果 WWWWWWWWWW
题目名称 驾车旅行 最终得分 0
用户昵称 0彼岸0 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-08 21:15:42
显示代码纯文本
program tour(input,output);
const max=1000;
type
  recordtype=record
  price,content:real
end;
var i,j,n,point,tail:longint;
    content,change,distance2,money,use:real;
    price,distance,con:array[0..max] of real;
    oil:array [0..max] of recordtype;

begin
  assign(input,'tour.in');
  assign(output,'tour.out');
  reset(input);
  rewrite(output);
  readln(distance[0],content,distance2,price[0],n);
  distance[n+1]:=distance[0];
    for i:=1 to n do readln(distance[i],price[i]);
        distance[0]:=0;
    for i:=n downto 0 do con[i]:=(distance[i+1]-distance[i])/distance2;
    for i:=0 to n do
    if con[i]>content then
       begin  halt end;
              money:=0; tail:=1; change:=0;
              oil[tail].price:=price[0]*2;
              oil[tail].content:=content;
              for i:=0 to n do
              begin
                point:=tail;
                while (point>=1) and (oil[point].price>=price[i]) do
                begin
                  change:=change+oil[point].content;
                  point:=point-1
                end;
              tail:=point+1;
              oil[tail].price:=price[i];
              oil[tail].content:=change;
              use:=con[i]; point:=1;
              while (use>1e-6) and (point<=tail) do
              if use>=oil[point].content
              then begin
                     use:=use-oil[point].content;
                     money:=money+oil[point].content*oil[point].price;
                     point:=point+1
                   end
           else begin
                oil[point].content:=oil[point].content-use;
                money:=money+use*oil[point].price;
                use:=0
                end;
          for j:=point to tail do oil[j-point+1]:=oil[j];
          tail:=tail-point+1;
          change:=con[i]
       end;
   writeln(money:0:2);
   close(input);
   close(output)
end.