01(CodeforcesB水平)CQU新生周末狂欢赛G - Escape
来源:互联网 发布:国内数据备份厂商 编辑:程序博客网 时间:2024/06/05 11:54
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.
Sample Input
121110
2
12118
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;}
- 01(CodeforcesB水平)CQU新生周末狂欢赛G - Escape
- 01(CodeforcesB水平)CQU新生周末狂欢赛F - Smile House
- 01(CodeforcesB水平)CQU新生周末狂欢赛 I - Phone Numbers
- 01(CodeforcesA水平)CQU新生周末狂欢赛E - Marks
- 01(CodeforcesA水平)CQU新生周末狂欢赛B - Insomnia cure
- 01(CodeforcesA水平)CQU新生周末狂欢赛C - Business trip
- 01(CodeforcesA水平)CQU新生周末狂欢赛D - Soft Drinking
- 01(CodeforcesC水平)CQU新生周末狂欢赛O- Pocket Book
- 01(CodeforcesC水平)CQU新生周末狂欢赛 N - Win or Freeze
- CQU&CQUPT联合狂欢赛小结
- 【2015ZUFE新生赛网络同步赛J】【水题 dfs】周末出游 是否所有点可达
- 20130709 【南华大学 ACM】 新生赛第二场 【G. Matrix】
- 新生训练赛round2--G. Maya Calendar(模拟)
- 4G:行业盛宴还是小众狂欢
- 现场赛经验 by CQU ACM/ICPC
- 【贪心+中位数】【新生赛3 1007题】 Problem G (K)
- 16哈理工新生赛 G FBI Tree (模拟二叉树后序遍历)
- 湖南大学ACM程序设计新生杯大赛(同步赛)G-The heap of socks【排序】
- UI:学习笔记
- Mac下VMware Fusion虚拟机安装Windows
- 图的邻接矩阵建立,广度深度搜索
- UIScrollView的Content Size, Content Inset属性
- java的Future和FutureTask
- 01(CodeforcesB水平)CQU新生周末狂欢赛G - Escape
- 不能导出p12和p12转pem
- [LeetCode]95.Unique Binary Search Trees II
- redhat下安装ruby2.2以及安装rubygems
- 悬停文字 悬浮提示 CtoolTipCtrl
- 三维重建:Dense Construction-KinectFusion的基本原理(尺度)
- 华为机试—字符串过滤
- 万向节死锁(Gimbal Lock)
- scala 简要:数组与映射