01(CodeforcesB水平)CQU新生周末狂欢赛G - Escape

来源:互联网 发布:国内数据备份厂商 编辑:程序博客网 时间:2024/06/05 11:54
G - Escape
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 148B

Description

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 ≤ 1001 ≤ t, f ≤ 101 ≤ c ≤ 1000).

Output

Output the minimal number of bijous required for the escape to succeed.

Sample Input

Input
121110
Output
2
Input
12118
Output
1

Hint

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.

题意:简单追击问题。公主偷了恐龙宝贝,开始逃往城堡,公主和恐龙的起点都在老巢处。公主在一个时间后会被恐龙发现,这时恐龙开始追击公主,因为可能会被追上,恐龙要抓到公主的时候公主会丢下一个宝贝,恐龙会把宝贝拿着返回老巢并整理然后继续追击。第一行是公主逃跑的速度,第二行是恐龙的速度,第三行是恐龙发现公主的时间,第四行是恐龙整理宝贝需要花费的时间,第五行是公主离城堡的距离是多远。问公主至少需要丢下几个宝贝,若恐龙与公主在城堡相遇,视公主已经安全不用再扔宝贝。

思路:这题有时间和位移两种算法,我采用的是位移计算法,循环的起点是恐龙的老巢,比较简单,但应当注意公主的速度可能比恐龙快或者相同代码如下。

#include <iostream>using namespace std;int main(){    int vp,vd,t,f,c,ans = 0;    cin>>vp>>vd>>t>>f>>c;    double x1 = vp*t*1.0;    while(1){        double markTime;        if(vd <= vp){//忽略这点wa了两次        break;        }        markTime = x1/(vd-vp);<span style="font-family: 'times new roman';">//恐龙从老巢出发追到公主的时间</span>        x1 += markTime*vp;        if(x1 >= c)break;        else ans++;        x1 += (markTime+f)*vp;    }    cout<<ans<<endl;    return 0;}



0 0
原创粉丝点击