[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
[关键字]:贪心
[题目大意]:守望者的跑步速度为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.
相关文章推荐
- TYVJ 1108 守望者的逃离 解题报告
- 1484. 守望者的逃离
- vijos1431[noip2007]守望者的逃离(背包动规)
- 1484. 守望者的逃离
- vijos1067守望者的逃离
- vijos1431[noip2007]守望者的逃离(背包动规)
- 守望者的逃离
- P1095 守望者的逃离
- 【?】【9908】守望者的逃离
- 守望者的逃离 动态规划+滚动数组
- 洛谷1095 守望者的逃离 解题报告
- noip2007 守望者的逃离 (贪心)
- Vijos P1431 守望者的逃离(动态规划,贪心)
- 守望者的逃离解题报告
- 守望者的逃离 洛谷p1095
- NOIP 2007普及组 守望者的逃离 DP详解
- SDNU__1091.守望者的逃离
- Sicily 1484. 守望者的逃离
- 【蓝桥第七周】守望者的逃离
- P1095 守望者的逃离