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
,
Output
Output the minimal number of bijous required for the escape to succeed.
Examples
Input | Output |
---|---|
1 2 1 1 10 |
2 |
Input | Output |
---|---|
1 2 1 1 8 |
1 |
Note
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.
题意:公主从洞穴沿直线逃往距离为
配合
显然
x公主=v公主∗t
,恶龙的方程看似复杂,但我们只关心两条曲线的交点。恶龙的曲线有一个很容易归纳出来的规律:每次从洞穴出发的后,都要经过追上公主+返回洞穴+藏好宝藏才能再次从龙穴出发,而追上公主和返回洞穴所用的时间是一样多的,都是
v公主×tiv恶龙−v公主
;用公式来描述就是
ti
时刻出发后,下一次出发的时刻
ti+1=2×v公主×tiv恶龙−v公主+f放好宝藏+ti
。答案就是求出在公主到达宫殿之前有多少个
ti
。
#include<stdio.h>
int vp,vd,t,f,c,i,j,k,temp;
int ans;
int main(){
while( scanf("%d %d %d %d %d",&vp,&vd,&t,&f,&c)==5){
if(vd<=vp){//恶龙的速度小于公主...永远也追不上,这里是为了保证后面的除法是正数
printf("0\n");
continue;
}
ans=0;
double bgt=t,edt=(double)c/vp;//初始化恶龙出发时间bgt为时间t,edt为公主到达的时间
double xp,xd;//公主和恶龙的位移
for(bgt=t;bgt+(vp*bgt)/(vd-vp)<edt;)
{//bgt+(vp*bgt)/(vd-vp)为下一次追到的时间,如果晚于公主到达宫殿的时间,那么之后的时间包括bgt都不需要宝石
ans++;//追到一次
bgt+=2*(vp*bgt)/(vd-vp)+f;//生成恶龙下一次出发的时间
}
printf("%d\n",ans);
}
}