Codeforces Round #105 (Div. 2) B. Escape
2015-08-11 15:08
127 查看
[align=center]B. Escape[/align]
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at vp miles per hour, and the dragon flies at
vd miles per hour. The dragon will discover the escape after
t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple
of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend
f hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is
c miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the
castle before the dragon reached her, and doesn't need an extra bijou to hold him off.
Input
The input data contains integers vp, vd, t, f and
c, one per line (1 ≤ vp, vd ≤ 100,
1 ≤ t, f ≤ 10,
1 ≤ c ≤ 1000).
Output
Output the minimal number of bijous required for the escape to succeed.
Sample test(s)
Input
Output
Input
Output
Note
In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return
to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this
she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou.
题目链接:http://codeforces.com/problemset/problem/148/B
题目大意:已知公主逃跑的速度vp和龙的速度vd,公主从龙穴逃跑 t 小时后龙发现并追赶公主,公主要到达距离龙穴 c 米处的目的C地才安全。在龙追赶公主的过程中,如果公主使用一颗钻石,那么该钻石能使龙返回到洞穴并在洞穴中停留 f 小时。求公主到达目的地最少使用多少颗钻石。
解题思路:过程模拟。在龙追上公主的一刻使用钻石。注意如果公主和龙同时到达目的地时不必再使用钻石。
代码如下:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The princess is going to escape the dragon's cave, and she needs to plan it carefully.
The princess runs at vp miles per hour, and the dragon flies at
vd miles per hour. The dragon will discover the escape after
t hours and will chase the princess immediately. Looks like there's no chance to success, but the princess noticed that the dragon is very greedy and not too smart. To delay him, the princess decides to borrow a couple
of bijous from his treasury. Once the dragon overtakes the princess, she will drop one bijou to distract him. In this case he will stop, pick up the item, return to the cave and spend
f hours to straighten the things out in the treasury. Only after this will he resume the chase again from the very beginning.
The princess is going to run on the straight. The distance between the cave and the king's castle she's aiming for is
c miles. How many bijous will she need to take from the treasury to be able to reach the castle? If the dragon overtakes the princess at exactly the same moment she has reached the castle, we assume that she reached the
castle before the dragon reached her, and doesn't need an extra bijou to hold him off.
Input
The input data contains integers vp, vd, t, f and
c, one per line (1 ≤ vp, vd ≤ 100,
1 ≤ t, f ≤ 10,
1 ≤ c ≤ 1000).
Output
Output the minimal number of bijous required for the escape to succeed.
Sample test(s)
Input
1 2 1 1 10
Output
2
Input
12118
Output
1
Note
In the first case one hour after the escape the dragon will discover it, and the princess will be 1 mile away from the cave. In two hours the dragon will overtake the princess 2 miles away from the cave, and she will need to drop the first bijou. Return
to the cave and fixing the treasury will take the dragon two more hours; meanwhile the princess will be 4 miles away from the cave. Next time the dragon will overtake the princess 8 miles away from the cave, and she will need the second bijou, but after this
she will reach the castle without any further trouble.
The second case is similar to the first one, but the second time the dragon overtakes the princess when she has reached the castle, and she won't need the second bijou.
题目链接:http://codeforces.com/problemset/problem/148/B
题目大意:已知公主逃跑的速度vp和龙的速度vd,公主从龙穴逃跑 t 小时后龙发现并追赶公主,公主要到达距离龙穴 c 米处的目的C地才安全。在龙追赶公主的过程中,如果公主使用一颗钻石,那么该钻石能使龙返回到洞穴并在洞穴中停留 f 小时。求公主到达目的地最少使用多少颗钻石。
解题思路:过程模拟。在龙追上公主的一刻使用钻石。注意如果公主和龙同时到达目的地时不必再使用钻石。
代码如下:
#include <cstdio> #include <cstring> #include <queue> using namespace std; const int maxn=1005; int main(void) { double vp,vd,t,f,c,s; int ans=0; scanf("%lf%lf%lf%lf%lf",&vp,&vd,&t,&f,&c); if(vp>vd) { printf("0\n"); return 0; } s=t*vp*vd/(vd-vp); //龙第一次追上公主是距龙洞的距离 while(s<c) //如果追上但还没到达目的地 { ans++; //使用一颗钻石 t=s/vd+f; //龙返回洞穴和停留的时间 s+=t*vp; //这段时间后公主距龙洞的距离 s=s*vd/(vd-vp); //再次追上时的距龙洞的距离 } printf("%d\n",ans); }
相关文章推荐
- MATLAB鼠标选取ROC区域
- LeetCode(173) Binary Search Tree Iterator
- LUA 局域网和网络
- ToolStrip类
- LoadRunner函数详解之web_reg_save_param_ex
- iOS-NSURLConnection网络请求,与服务器交互的请求注意点和实现方式
- 转:【拓扑排序详解】+【模板】
- Leetcode#11||Container With Most Water
- 黑马程序员——C语言笔记之printf函数与格式控制符
- HDOJ 4463 Outlets(最小生成树--prime)
- SQL-多实例造成***S故障
- 使用SeasLog打造PHP项目中的高性能日志组件(一)
- HDU-1010 Tempter of the Bone
- Android屏幕适配 一
- ppt转pdf网址
- 【转载】Perl中的引用
- 转载:安装ie driver和chrome driver
- HDOJ2896病毒侵袭【AC自动机】
- iOS通过pickerView自定义简单的时间选择器
- 详解网站WEB日志格式