Huazhong Agricultural University The fourth session of the Program Design Contest network synchronization race I

Source: Internet
Author: User

Problem i:catching dogstime limit:1 Sec Memory limit:128 MB
submit:1130 solved:292
[Submit] [Status] [Web Board] Description

Diao Yang keeps many dogs. But today he dogs all run away. Diao Yang had to catch them. To simplify the problem, we assume Diao Yang and all the dogs is on a number axis. The dogs is numbered from 1 to N. At first Diao Yang was on the original point and he is v. The ithDog is on the point AI and it speed is VI . Diao Yang would catch the dog by the order of their numbers. which means only if Diao Yang have 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'll run toward the dog and he'll never stop or change his direction until H E has caught the dog. Now Diao Yang wants to know how long it takes for him to catch all the dogs.

Input

There is multiple test cases. In each test case, the first line contains the positive integers n(n≤10) and v(1≤v≤10) . Then n lines followed, each line contains the 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 would end by EOF.

Output

For each test case, output the answer. The answer should is rounded to 2 digits after decimal point. If Diao Yang cannot catch all of the dogs, output "bad Dog" (without quotes).

Sample Input
2 5-2-32 31 62-21 10-11 1-1-1
Sample Output
6.000.250.00Bad Dog

Test instructions: Master Catch dog topic owner owns N dog owner speed for v N dog number after having corresponding initial position ai with initial velocity vi vi>0 direction right
When the master catches the first dog, he can catch the first i+1 dog if he can catch all the dogs. Output "Bad Dog";



#include <iostream>#include<cstring>#include<cstdio>#include<cmath>using namespacestd;Doublen,v;structNode {DoublePOS; Doublev;} n[ the];Doubleinit=0;DoubleTimDoubleTargetDoubleVV) {    DoubleDIS,VVV; if(init>target) {Dis=init-Target; VVV=v+VV; }    Else{dis=target-Init; VVV=v-VV; }       if(dis==0)    return 0; if(vvv<=0)    return-1; returndis*1.0/vvv*1.0;}intMain () { while(SCANF ("%LF%LF", &n,&v)! =EOF) {memset (N,0,sizeof(N)); intflag=0;  for(intI=1; i<=n;i++) scanf ("%LF%LF",&n[i].pos,&n[i].v); Doublet=0, tt=0;; Init=0;  for(intI=1; i<=n;i++) {T=tim (n[i].pos+tt*n[i].v,n[i].v); if(t<0) {flag=1;  Break; }             if(t>0) TT+=T; Init=n[i].pos+n[i].v*tt; }        if(flag) cout<<"Bad Dog"<<Endl; Elseprintf ("%.2f\n", TT); }    return 0;}

Huazhong Agricultural University The fourth session of the Program Design Contest network synchronization race I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.