zoukankan      html  css  js  c++  java
  • 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.

    Sample Input

    Input

    1
    2
    1
    1
    10
    

    Output

    2
    

    Input

    1
    2
    1
    1
    8
    

    Output

    1
    

    Sample Output

    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.

    题目大意:龙追公主,龙的速度为vd mile/h,公主速度为vp mile/h,龙在t小时后发现公主从老巢逃跑并开始追,一旦龙追上公主,公主可以丢个东西,这时候龙要拿着这个东西回老巢再用f小时研究它,然后重新出发开始追公主,龙的老巢和王宫相距c mile,问公主最少要准备多少个这样的东西才能安全回王宫,如果龙和公主同时到王宫,算公主已经安全到达

    #include <stdio.h>
    int main()
    {
        double vp,vd,t,f,c,x,y,t1,t2;
        int sum=0;
        while(scanf("%lf%lf%lf%lf%lf",&vp,&vd,&t,&f,&c)!=EOF)
        {
            sum=0;
            if(vp>vd)//不可能追上
                printf("0
    ");
            else
            {
                x=t*vp;//公主在龙发现之前走的
                t1=x/(vd-vp);//龙追上公主的时间
                x+=t1*vp;//龙追上公主时公主的位置
                while(x<c)
                {
                    sum++;
                    t2=x/vd+f;//龙回去研究完时间
                    x+=t2*vp;//公主的位置
                    t1=x/(vd-vp);
                    x+=t1*vp;
                }
                printf("%d
    ",sum);
            }
        }
        return 0;
    }
  • 相关阅读:
    【bzoj2500】幸福的道路 树形dp+单调队列
    【ARC069F】Flags 2-sat+线段树优化建图+二分
    【bzoj2437】[Noi2011]兔兔与蛋蛋 二分图最大匹配+博弈论
    剑指offer——树的子结构
    剑指offer——反转链表
    腾讯算法岗面试算法题——计数排序
    作业帮面试题
    剑指offer——重建二叉树
    剑指offer——二维数组中的查找
    删除链表中重复的结点
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702829.html
Copyright © 2011-2022 走看看