codeforces-148B-Escape

来源:互联网 发布:mac系统偏好设置卡死 编辑:程序博客网 时间:2024/06/04 19:07

148B-Escape


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 ≤ 100, 1 ≤ t, f ≤ 10, 1 ≤ c ≤ 1000).

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

Input
1
2
1
1
10
Output
2

Input
1
2
1
1
8
Output
1

题目链接:cf-148B

题目大意:公主逃跑的速度为vp,龙追赶的速度为vd,公主逃跑之后龙要经过t秒发现。如果龙追上的公主,公主使用道具,龙将原速返回cave,并且f秒之后重新追出。cave和城堡之间有c米距离,问公主至少需要使用道具几次。

ps:
1. 如同时到达城堡,则算公主逃脱成功
2. 公主速度比龙快,那么龙永远也追不上

这道题比赛的时候被坑了好久,orz,因为我忘记加龙返回cave的同时,公主前进的路程。还有使用EPS好像出现未知bug

以下是代码:

#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>#include <string>#include <set>#include <functional>#include <numeric>#include <sstream>#include <stack>#include <map>#include <queue>#include<iomanip>#define EPS 10-8using namespace std;int main(){    double vp,vd,t,f,c;    cin >> vp >> vd >> t >> f >> c;    if (vp >= vd)    {        cout << 0 << endl;        return 0;    }    int ans = 0;    double begin = vp * t;  //记录追赶的开始  公主的位置        while(1)    {        double T = begin * 1.0 / (vd - vp);        begin += vp * T;        if (begin - c >= 0) break;        else        {            begin += (T + f) * vp;            ans++;        }    }    cout << ans << endl;    return 0;}
0 0