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;}
- CodeForces 148B - Escape
- codeforces-148B-Escape
- CodeForces 148B Escape
- CodeForces - 148B B - Escape xjb模拟
- Codeforces B. Escape
- B -Escape CodeForces
- Codeforces Round #105 (Div. 2) B. Escape
- codeforces 148 div2 B
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 264A Escape from Stones dfs
- codeforces-264A-Escape from Stones
- Codeforces 265 Escape from Stones 思维(极限)
- escape
- escape
- escape
- JFinal在网络服务端开发中的位置
- 计算完全最短路径的Floyd算法
- 有重复元素的排列问题
- PagerAdapter学习
- python笔记1
- codeforces-148B-Escape
- android 自定义View知识点
- 【BZOJ 2120】 数颜色 (乱搞分块,直指暴力)
- forward和redirect的区别
- 《Linux内核设计与实现》——第1、2章(内核简介)
- Hadoop MapReduce模块 Module 4: MapReduce
- 关于Java增强for循环的一点儿思考
- 利用递归实现10进制转化成任意进制
- display:none和visibility:hidden的区别?