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