您的位置:首页 > 其它

[Tyvj1108 守望者的逃离]

2011-11-01 11:04 232 查看
[题目来源]:NOIP2007普及组

[关键字]:贪心

[题目大意]:守望者的跑步速度为17m/s,守望者拥有闪烁法术,可在1s内移动60m,每次使用闪烁法术都会消耗魔法值10点。守望者的魔法值恢复的速度为4点/s,只有处在原地休息状态时才能恢复。现在已知守望者的魔法初值M,他所在的初始位置与岛的出口之间的距离S,岛沉没的时间T。计算如何在最短的时间内逃离荒岛,若不能逃出,则输出守望者在剩下的时间能走的最远距离。

//======================================================================

[分析]:AC做法是贪心。易证闪烁最然需要回魔,但闪烁之后一定走的比跑要远,所以只要有魔就闪,没魔就回魔。注意到最后时,如果没时间进行下一次回魔加闪烁就要跑。还有如果到最后时,如果跑到终点的时间和进行下一次回魔加闪烁时间一样,要判断哪个更远:因为会磨时间+闪烁时间只有3s或4s两种可能,但是其中17*4=68,但闪烁只有60.

[代码]:

View Code

program Project1;
var
m, s, t: longint;

procedure work;
var
ma, wt, ws, temp, t1: longint;
begin
ma := m;
ws := 0;
wt := 0;
while (ws < s) and (wt < t) do
begin
inc(wt);
if ma >= 10 then
begin
inc(ws,60);
dec(ma,10);
//writeln(wt,' k ',ws);
continue;
end;
if ma < 10 then
begin
temp := 10-ma;
if temp mod 4 = 0 then temp := temp div 4 else temp := temp div 4+1;
if t-wt+1 < temp+1 then
begin
inc(ws,17);
continue;
end;
t1 := s-ws;
if t1 mod 17 = 0 then t1 := t1 div 17 else t1 := t1 div 17+1;
if t1 = temp+1 then
if s-ws > 60 then
begin
inc(ws,17);
continue;
end;
if t1 < temp+1 then
begin
inc(ws,17);
continue;
end;
inc(ma,4);
//writeln(wt,' l ',ws);
end;
end;
if ws >= s then
begin
writeln('Yes');
writeln(wt);
end
else
begin
writeln('No');
writeln(ws);
end;
end;

begin
assign(input,'d:\1.in');reset(input);
assign(output,'d:\1.out');rewrite(output);
readln(m,s,t);
work;
close(input);
close(output);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: