【CF#148B】Escape(模拟)
題干:
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.
Examples
Input
1 2 1 1 10Output
2Input
1 2 1 1 8Output
1Note
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.
題目大意:公主逃跑的速度為vp,龍追趕的速度為vd,公主逃跑之后龍要經(jīng)過t秒發(fā)現(xiàn)。如果龍追上的公主,公主使用道具,龍將原速返回cave,并且f秒之后重新追出。cave和城堡之間有c米距離,問公主至少需要使用道具幾次。
ps:?
1. 如同時到達(dá)城堡,則算公主逃脫成功?
2. 公主速度比龍快,那么龍永遠(yuǎn)也追不上
注意 ?: 我忘記加龍返回cave的同時,公主前進(jìn)的路程。p和d判斷的時候,如果使用EPS=1e-8好像出現(xiàn)未知bug
解題報告:
? ? ?按照題意模擬過程,注意用double。
AC代碼:
#include<iostream> #include<cstdio> using namespace std; int main() {double p,d,t,f,c;scanf("%lf%lf%lf%lf%lf",&p,&d,&t,&f,&c);if(p>=d) {printf("0\n");return 0 ;}double cur=0;cur+=t*p;int sum=0;double t1;t1=cur/(d-p);cur+=t1*p;double t2=0;while(cur<c){sum++;t2=cur/d;cur+=t2*p;cur+=f*p;t1=cur/(d-p);cur+=t1*p;}cout <<sum <<endl;return 0 ;}總結(jié)
以上是生活随笔為你收集整理的【CF#148B】Escape(模拟)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 建行信用卡逾期查询 掌握好三点技巧远离逾
- 下一篇: 2017最值得办的信用卡 诱人权益等着你