码迷,mamicode.com
首页 > 其他好文 > 详细

YT14-HDU-James跳桥

时间:2015-02-03 09:34:02      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:c++   iostream   namespace   编程   博客   

Problem Description

Once again, James Bond is fleeing from some evil people who want to see him dead. Fortunately, he has left a bungee rope on a nearby highway bridge which he can use to escape from his enemies. His plan is to attach one end of the rope to the bridge, the other end of the rope to his body and jump off the bridge. At the moment he reaches the ground, he will cut the rope, jump into his car and be gone. 

Unfortunately, he had not had enough time to calculate whether the bungee rope has the right length, so it is not clear at all what is going to happen when he jumps off the bridge. There are three possible scenarios: 
The rope is too short (or too strong), and James Bond will never reach the ground. 
The rope is too long (or too weak), and James Bond will be going too fast when he touches the ground. Even for a special agent, this can be very dangerous. You may assume that if he collides at a speed of more than 10 m/s, he will not survive the impact. 
The rope‘s length and strength are good. James Bond touches the ground at a comfortable speed and can escape. 
As his employer, you would like to know whether James Bond survives or whether you should place a job ad for the soon-to-be vacant position in the local newspaper. Your physicists claim that: 
The force with which James is pulled towards the earth is 
9.81 * w, 
where w is his weight in kilograms and 9.81 is the Earth acceleration in meters over squared seconds. 
Mr. Bond falls freely until the rope tautens. Then the force with which the bungee rope pulls him back into the sky depends on the current length of the rope and is 
k * Δl, 
where Δl is the difference between the rope‘s current length and its nominal, unexpanded length, and k is a rope-specific constant. 
Given the rope‘s strength k, the nominal length of the rope l in meters, the height of the bridge s in meters, and James Bond‘s body weight w, you have to determine what is going to happen to our hero. For all your calculations, you may assume that James Bond is a point at the end of the rope and the rope has no mass. You may further assume that k, l, s, and w are non-negative and that s < 200.

The input contains several test cases, one test case per line. Each test case consists of four floating-point numbers (k, l, s, and w) that describe the situation. Depending on what is going to happen, your program must print "Stuck in the air.", "Killed by the impact.", or "James Bond survives.". Input is terminated by a line containing four 0s, this line should not be processed.

Sample Input

350 20 30 75
375 20 30 75
400 20 30 75
425 20 30 75
450 20 30 75
400 20 30 50
400 20 30 80
400 20 30 85
0 0 0 0

Sample Output

Killed by the impact.
James Bond survives. 
James Bond survives. 
James Bond survives. 
Stuck in the air.
Stuck in the air.
James Bond survives. 
Killed by the impact.

代码如下:

#include <iostream>
#include <cmath>
using namespace std;
const double g=9.81;                   //重力加速度
int main()
{
    double k,l,s,w;
    double E0,E1,E2,E4;
    while (cin>>k>>l>>s>>w)
    {
        if (k==0&&l==0&&s==0&&w==0)
            break;
        E0=0.5*k*(s-l)*(s-l);          //弹性势能
        E1=w*g*s;                      //重力势能
        E2=0.5*w*10*10;                //最大动能
        E4=E1-E0;                      //重力势能与弹力势能抵消后剩下的支持JAMES下落的能量
        if (l>s)
        {
            if (E1>E2)
                cout<<"Killed by the impact."<<endl;
            else
                cout<<"James Bond survives."<<endl;
        }
        else
        {
            if(E0>E1)
                cout<<"Stuck in the air."<<endl;
            else if(E4<E2)
                cout<<"James Bond survives."<<endl;
            else
                cout<<"Killed by the impact."<<endl;
        }
    }
    return 0;
}

运行结果:

技术分享


简单的物理问题,,,好在我高中的班主任是物理老师,一些能量间的转换什么的还是记得一些的,可是我忘光了物理公式。。。


YT14-HDU-James跳桥

标签:c++   iostream   namespace   编程   博客   

原文地址:http://blog.csdn.net/liuchang54/article/details/43445243

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!