小岛沉没(pascal或basic)

来源:百度知道 编辑:UC知道 时间:2024/05/31 00:15:06
有一个人所在的小岛即将沉没,他可以跑或走,跑步速度是60m/s,但每秒要消耗10点魔法;走路速度是17m/s,不消耗魔法。他可以休息,每秒恢复4点魔法,但不能做其他事。现在已知魔法m、路程s、时间t,求他能否逃脱?
若能,打印yes和最少时间,若不能,打印no和他能逃离的最长路程。
跑步、走路、休息按整秒计算

这个不就今年NOIP复赛普及组的第3题吗?守望者的逃离!!楼主去网上搜一下“守望者的逃离”,就有程序了!!!

program escape(input,output);
var

m,ss,t,ma,ta,tt,i:longint;
s:longint;

begin

assign(input,'escape.in');
assign(output,'escape.out');

reset(input);rewrite(output);
readln(m,s,t);
ss:=0;tt:=0;
ta:=m div 10;ma:=m mod 10;
if ta>=t then
while (s>ss) and (tt<t) do
begin
ss:=ss+60;inc(tt);
end else
begin ss:=ss+60*ta;tt:=tt+ta;end;
while (s-ss>0) and ((t-tt)>0) do
begin
if (s-ss<=17) then begin ss:=ss+17;inc(tt);continue;end;
if ((s-ss>17)and(s-ss<=34)and (ma<6)) then begin ss:=ss+17;inc(tt);continue;end;
if ((s-ss>34)and (s-ss<=51)and (ma<2)) then begin ss:=ss+17;inc(tt);continue;end;
if ((s-ss>51)and (s-ss<=68)) then begin ss:=ss+17;inc(tt);continue;end;
if ((t-tt<7) and (ma<2)) or ((t-tt<3) and (