vijos P1253 旅行家的预算

发布时间:2024-05-15 09:23 发布:上海旅游网

问题描述:

只能过去4个测试点。。。谈心的算法应该没有什么问题。。。可能是循环处理中有些变量的范围没有定义好。。。本人疲乏,看不出来了~~

请有识者明示~~

程序代码如下:

program P1253;

var
c,d1,d2,p,tot:real;
n,i,t:longint;
pi,di,use,ci,si:array[0..1000]of real;

function find(i:longint):longint;
var
x,k:longint;
min:real;
begin
k:=0;
min:=10000000;
for x:=1 to i do
if (ci[x]>0)and(pi[x]<min) then
begin
k:=x;
min:=pi[x];
end;
exit(k);
end;

begin
di[0]:=0;
readln(d1,c,d2,p,n);
pi[0]:=p;di[n+1]:=d1;
for i:=1 to n+1 do
begin
readln(di[i],pi[i]);
si[i]:=di[i]-di[i-1];
use[i]:=si[i]/d2;
if si[i]>d2*c then
begin
writeln(-1);
halt;
end;
end;

for i:=0 to n do
ci[i]:=c;

while si[i]>0 do
begin
t:=find(i);
if ci[t]*d2>=si[i] then
begin
ci[t]:=ci[t]-si[i]/d2;
si[i]:=0;
end
else
begin
si[i]:=si[i]-ci[t]*d2;
ci[t]:=0;
end;
end;

for i:=0 to n do
tot:=tot+pi[i]*(c-ci[i]);
writeln(tot:0:2);
readln;
readln;
end.

问题解答:

vijos P1253 旅行家的预算这个旅游问答期待您的解答,请登录账号或关注微信公众号回答这个问题。

热点新闻