hdoj 3086 Need for Speed(解方程)

【题目大意】:一个警察与Jiaoshou的距离为S,而且他们的运动速度满足方程v=a*t+b,已知警察和Jiaoshou的a和b的值,问警察能否追上Jiaoshou,追上的话需要多少时间。


【解题思路】:数学题,解方程


【代码】:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <cctype>
#include <map>
#include <iomanip>
                   
using namespace std;
                   
#define eps 1e-8
#define pi acos(-1.0)
#define inf 1<<30
#define pb push_back
#define lc(x) (x << 1)
#define rc(x) (x << 1 | 1)
#define lowbit(x) (x & (-x))
#define ll long long

int main() {
    int T;
    double s,ax,bx,ay,by;
    double a,b,c,p,r1,r2,m,d;
    bool flag;
    cin >> T;    
    while(T--){
        m=0;
        flag=true;
        scanf("%lf",&s);
        scanf("%lf%lf",&ax,&bx);
        scanf("%lf%lf",&ay,&by);
        if(ay!=ax){
            d=(by-bx)*(by-bx)+2*(ay-ax)*s;
            if(d<0) flag=false;
            else{
                r1=(bx-by-sqrt(d))/(ay-ax);
                r2=(bx-by+sqrt(d))/(ay-ax);
                if(r1>=0 && r2>=0){
                    if(r1<r2)  m=r1;
                    else  m=r2;
                }
                else if(r1>=0 && r2<0)
                        m=r1;
                else if(r2>=0 && r1<0)
                        m=r2;
                else{
                    flag=false;                    
                }
           }                
        }
        else{
            if(by!=bx)
                m=s/(by-bx);
            else  m=-1;
            if(m<0)  flag=false;
            else flag=true;
        }
        if (flag) printf("Oh,God!Jiaoshou will be catched after %.3f minutes.\n" ,m);
        else printf("Good driver,Jiaoshou!\n" );        
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值