HDU3086-追及问题-解一元二次方程组
来源:互联网 发布:淘宝店铺音乐怎么换 编辑:程序博客网 时间:2024/05/10 05:37
Need for Speed
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 759 Accepted Submission(s): 214
Problem Description
Jiaoshou is a fan of “Need for Speed”, a famous game which most people have played. Recently, Jiaoshou had cleared “Need for Speed Undercover”. In this game, Jiaoshou acted as a spy. To prove that he is not a spy, Jiaoshou must do some evil things frequently. So lots of police cars often ran after him. In order to escape from the chase, Jiaoshou need to accelerate his Bugatti Veyron.
To simplify this problem, we just assume that only one police car ran after Jiaoshou. And Bugatti Veyron’s speed is vx. The police car’s speed is vy. v is a function of first degree or a constant, as the form of a*m+b. In this form, m means the minute that the car has run.
Now Jiaoshou is S meters ahead. Jiaoshou like to know if he could escape from the chase. He want you to write a program to solve this problem.
To simplify this problem, we just assume that only one police car ran after Jiaoshou. And Bugatti Veyron’s speed is vx. The police car’s speed is vy. v is a function of first degree or a constant, as the form of a*m+b. In this form, m means the minute that the car has run.
Now Jiaoshou is S meters ahead. Jiaoshou like to know if he could escape from the chase. He want you to write a program to solve this problem.
Input
The input contains several tests. The first line of the input is a single integer T (T<1000) which is the number of test cases. Then T test cases follow.
Each test case contains three lines. The first line contains a single real number S (0<S<=10^6) , as the problem has described. The second line contains two real numbers ax, bx, indicating Bugatti Veyron’s speed is ax*m+bx. The last line also contains two real numbers ay, by, indicating the police car’s speed is ay*m+by. All numbers are range from -1000 to 1000, except S.
Each test case contains three lines. The first line contains a single real number S (0<S<=10^6) , as the problem has described. The second line contains two real numbers ax, bx, indicating Bugatti Veyron’s speed is ax*m+bx. The last line also contains two real numbers ay, by, indicating the police car’s speed is ay*m+by. All numbers are range from -1000 to 1000, except S.
Output
If Jiaoshou can escape from the chase, please output “Good driver,Jiaoshou!”. Otherwise, please output the real number M rounded to three digits after the decimal point , in the form of “Oh,God!Jiaoshou will be catched after M minutes.”
Sample Input
21000 100 2010000 10 0
Sample Output
Oh,God!Jiaoshou will be catched after 10.000 minutes.Good driver,Jiaoshou!
Author
Water Problem SecKill Expert
Source
HDU 2nd “Vegetable-Birds Cup” Programming Open Contest
思路:
很明确的思路,A的速度为ax*m+bx,B的速度为ay*m+by,A在B之前dist远处,问B能否追上A,如果能追上,那么经过多少分钟才能
追上?建立时间-速度的二维坐标,那么速度对时间的积分即为距离(物理公式:s=vt),ax+b的定积分为ax^2/2+bx,所以,化简可以得到一
个一元二次方程组,接下来的就是解方程组了.
/*Tdistax bxay by追及问题:(ay-ax)/2*m^2 + (by-bx)*m - dist = 0 判断是否有解*/#include <iostream>#include <math.h>using namespace std;const double esp = 0.0000000000001;bool isExistSolution;double ans1,ans2;void solve_equation(double a,double b,double c) //ax^2+bx+c=0{if (fabs(a) < esp){if (fabs(b) > 0){isExistSolution = true;ans1 = ans2 = -c / b;// 分母不能为0!!}elseisExistSolution = false;return;}double deltar = b*b - 4.0*a*c;if (deltar < 0)isExistSolution = false;else{isExistSolution = true;deltar = sqrt(deltar)/(2.0*a);b = (-b)/(2.0*a);ans1 = b + deltar;ans2 = b - deltar;}}int main(){#ifndef ONLINE_JUDGEfreopen("2.txt","r",stdin);#endifint T;double dist, ax, bx, ay, by;cin >> T;while (T--){cin >> dist >> ax >> bx >> ay >> by;solve_equation(0.5*(ay-ax),by-bx,-dist);if (!isExistSolution)puts("Good driver,Jiaoshou!");else{if (ans1 > 0)printf("Oh,God!Jiaoshou will be catched after %.3lf minutes.\n",ans1);else if (ans2 > 0)printf("Oh,God!Jiaoshou will be catched after %.3lf minutes.\n",ans2);elseputs("Good driver,Jiaoshou!");}}return 0;}
0 0
- HDU3086-追及问题-解一元二次方程组
- 计算一元二次方程组
- 一元二次方程组
- 一元二次方程组膜下解
- CodeForces - 630N Forecast (解一元二次方程组)
- C语言求一元二次方程组的解
- 求一元二次方程组ax^2+bx+c的解
- 利用C语言求解一元二次方程组的解
- 线性表写一元二次方程组
- 用python求解一元二次方程组
- 一元二次方程组(改进delta<0)
- 4 利用简单分支计算一元二次方程组的根
- 牛顿迭代法解一元方程组
- 牛顿迭代法解一元方程组
- 解一元二次不等式
- VB解一元二次方程式
- 解一元线性同余方程组模板
- 解一元线性同余方程组
- 论涂装的重要性
- Java事件处理机制- 事件监听器的四种实现方式
- DIV Display属性和Visibility属性
- SPOJ STAMPS
- Android的入门学习一
- HDU3086-追及问题-解一元二次方程组
- 在iOS上使用ffmpeg播放视频
- 归去来
- 编译Android下可用的FFmpeg+x264
- webgrid 用法 asp.net mvc
- OkHttp–支持SPDY协议的高效HTTP库
- HDU3339 最短路加01背包
- DroidDraw使用
- hibernate一对一