zoukankan      html  css  js  c++  java
  • 华中农业大学校赛 I Catching Dogs

    Catching Dogs

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 1140  Solved: 298
    [Submit][Status][Web Board]

    Description

       Diao Yang keeps many dogs. But today his dogs all run away. Diao Yang has to catch them. To simplify the problem, we assume Diao Yang and all the dogs are on a number axis. The dogs are numbered from 1 to n. At first Diao Yang is on the original point and his speed is v. The ith dog is on the point ai and its speed is vi . Diao Yang will catch the dog by the order of their numbers. Which means only if Diao Yang has caught the ith dog, he can start to catch the (i+1)th dog, and immediately. Note that When Diao Yang catching a dog, he will run toward the dog and he will never stop or change his direction until he has caught the dog. Now Diao Yang wants to know how long it takes for him to catch all the dogs.

    Input

        There are multiple test cases. In each test case, the first line contains two positive integers n(n≤10) andv(1≤v≤10). Then n lines followed, each line contains two integers ai(|ai|≤50) and vi(|vi|≤5). vi<0 means the dog runs toward left and vi>0 means the dog runs toward right. The input will end by EOF.

    Output

        For each test case, output the answer. The answer should be rounded to 2 digits after decimal point. If Diao Yang cannot catch all the dogs, output “Bad Dog”(without quotes).

    Sample Input

    2 5
    -2 -3
    2 3
    1 6
    2 -2
    1 1
    0 -1
    1 1
    -1 -1

    Sample Output

    6.00
    0.25
    0.00
    Bad Dog

    HINT

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    struct Node
    {
        double pos;
        double v;
    }dog[15];
    double cal(double v,double dogv)
    {
        if(v>0&&dogv>0)
        {
            if(v>dogv) return v-dogv;
            else return 0;
        }
        if(v<0&&dogv<0)
        {
            if(v<dogv) return dogv-v;
            else return 0;
        }
        if(v*dogv<=0) return fabs(v+0.0)+fabs(dogv);
    }
    int main()
    {
        int n;
        double v;
        while(scanf("%d%lf",&n,&v)!=EOF)
        {
            if(n<=0) continue;
            for(int i=0;i<n;i++)
            {
                scanf("%lf%lf",&dog[i].pos,&dog[i].v);
            }
            double nt=0;
            double ans=0;
            double posp=0;
            bool flag=true;
            for(int i=0;i<n;i++)
            {
    
                dog[i].pos=dog[i].pos+(dog[i].v*ans);
                if(fabs(posp-dog[i].pos)<1e-6) continue;
                if(posp>dog[i].pos) v=-fabs(v);
                if(posp<dog[i].pos) v=fabs(v);
                double catv=cal(v,dog[i].v);
                if(catv==0) {printf("Bad Dog
    ");flag=false;break;}
                double catx=posp-dog[i].pos;
               // cout<<catx<<"**"<<catv<<endl;
                nt=catx/catv;
                posp=fabs(nt)*v+posp;
               // cout<<"posp**"<<posp<<endl;
                ans+=fabs(nt);
            }
            if(flag) printf("%.2lf
    ",ans);
        }
        return 0;
    
    }
    View Code

    模拟题,水题。

    考虑dogv=0的这种情况。

  • 相关阅读:
    一篇文章教会你在Windows和Linux系统下搭建Nginx
    【红日安全-VulnStack】ATT&CK实战系列——红队实战(二)
    绕过WAF进行常见Web漏洞利用
    Mac mysql 5.7.x 设置服务开机自启动
    Mac mysql 5.7启动报错,解决之道 The server quit without updating PID file
    阿里云Centos7 安装mysql5.7 报错:./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    Python 反序列化漏洞学习笔记
    Jmeter二次开发——基于Java请求
    环境篇:Atlas2.1.0兼容CDH6.3.2部署
    synchronized 是王的后宫总管,线程是王妃
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5496171.html
Copyright © 2011-2022 走看看