1樓:
有兩種方法:
1:program trip(input,output);
const max=1000;
var i,n:longint;
c,d2:real;
p,d,consume:array[0..max] of real;
function minp(b,e:longint):longint;
var i,k:longint;
tempminp:real;
begin
tempminp:=p[e]; k:=e;
for i:=e-1 downto b do
if p[i]start
then money:=money(start,k,rest)+money(k,stop,0)
else if d[stop]-d[start]<=d2*c
then money:=((d[stop]-d[start])/d2-rest)*p[start]
else begin
k:=minp(start+1,stop-1);
if d[k]-d[start]<=d2*c
then
money:=(c-rest)*p[start]+money(k,stop,c-(d[k]-d[start])/d2)
else money:=money(start,k,rest)+money(k,stop,0)
endend
end;
begin
assign(input,'trip.in');
assign(output,'trip.out');
reset(input);
rewrite(output);
readln(d[0],c,d2,p[0],n);
d[n+1]:=d[0];
for i:=1 to n do readln(d[i],p[i]);
d[0]:=0;
for i:=n downto 0 do consume[i]:=(d[i+1]-d[i])/d2;
for i:=0 to n do
if consume[i]>c then
begin writeln('no solution'); close(output);halt end;
writeln(money(0,n+1,0):0:2);
close(input);
close(output)
end.
2:program trip2(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,consume:array[0..max] of real;
oil:array [0..max] of recordtype;
begin
assign(input,'trip.in');
assign(output,'trip.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 consume[i]:=(distance[i+1]-distance[i])/distance2;
for i:=0 to n do
if consume[i]>content then
begin writeln('no solution'); 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:=consume[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
endelse 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:=consume[i]
end;
writeln(money:0:2);
close(input);
close(output)
end.
2樓:騎小豬追星星
program ex5_2(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,consume:array[0..max] of real;
oil:array [0..max] of recordtype;
begin
write('input di,c,d2,p:'); readln(distance[0],content,distance2,price[0]);
write('input n:'); readln(n); distance[n+1]:=distance[0];
for i:=1 to n do
begin
write('input d[',i,'],','p[',i,']:');
readln(distance[i],price[i])
end;
distance[0]:=0;
for i:=n downto 0 do consume[i]:=(distance[i+1]-distance[i])/distance2;
for i:=0 to n do
if consume[i]>content then
begin writeln('no solution'); 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:=consume[i]; point:=1;
while (use>1e-6) and (point=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:=consume[i]
end;
writeln(money:0:2)
end.
問一道數學題目,問一道數學題
很樂意幫忙 同學你好,此時是早上十點五十六分.列方程解答.分別設小明和老師的速度為v1,v2.根據提議得 v1 4 v2 8 4 化簡上式得 v2 v1 2v1v2 v1 1 4 km min v2 1 2 km min 則老師從開始到第一次追撒還能夠小明所用時間為 4 1 2 8 min 老師從第...
問一道數學題,問一道數學題目
依題意可知該三稜錐為正三稜錐,稜長為1,所以求半徑r 6 4,所以球的體積v 4 r 3 3 6 8 所以選c 等腰梯形abcd,ab 2dc 2,角dab 60 e為ab中點,將 ade和 bec分別沿ed,ec向上折起,使a,b重合於點p,則三稜錐p dce的外接球的體積為 a.4倍根號3 27...
問一道物理題目,問一道物理題
解 72km h 20m s,114km h 31.6m s設摩托車達最高速度用時為t 追上用時為t 1t vm a 31.6 4 7.9 s摩托車 卡車位移分別為s1 s 2 摩托車先勻加速,後勻速。追上卡車時 s1 s21 2 a t2 v m t 1 t 5 t 1 20 t 1 19.4 s...