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

  1. 2 5
  2. -2 -3
  3. 2 3
  4. 1 6
  5. 2 -2
  6. 1 1
  7. 0 -1
  8. 1 1
  9. -1 -1

Sample Output

  1. 6.00
  2. 0.25
  3. 0.00
  4. Bad Dog

HINT

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<math.h>
  4. using namespace std;
  5. struct Node
  6. {
  7. double pos;
  8. double v;
  9. }dog[];
  10. double cal(double v,double dogv)
  11. {
  12. if(v>&&dogv>)
  13. {
  14. if(v>dogv) return v-dogv;
  15. else return ;
  16. }
  17. if(v<&&dogv<)
  18. {
  19. if(v<dogv) return dogv-v;
  20. else return ;
  21. }
  22. if(v*dogv<=) return fabs(v+0.0)+fabs(dogv);
  23. }
  24. int main()
  25. {
  26. int n;
  27. double v;
  28. while(scanf("%d%lf",&n,&v)!=EOF)
  29. {
  30. if(n<=) continue;
  31. for(int i=;i<n;i++)
  32. {
  33. scanf("%lf%lf",&dog[i].pos,&dog[i].v);
  34. }
  35. double nt=;
  36. double ans=;
  37. double posp=;
  38. bool flag=true;
  39. for(int i=;i<n;i++)
  40. {
  41.  
  42. dog[i].pos=dog[i].pos+(dog[i].v*ans);
  43. if(fabs(posp-dog[i].pos)<1e-) continue;
  44. if(posp>dog[i].pos) v=-fabs(v);
  45. if(posp<dog[i].pos) v=fabs(v);
  46. double catv=cal(v,dog[i].v);
  47. if(catv==) {printf("Bad Dog\n");flag=false;break;}
  48. double catx=posp-dog[i].pos;
  49. // cout<<catx<<"**"<<catv<<endl;
  50. nt=catx/catv;
  51. posp=fabs(nt)*v+posp;
  52. // cout<<"posp**"<<posp<<endl;
  53. ans+=fabs(nt);
  54. }
  55. if(flag) printf("%.2lf\n",ans);
  56. }
  57. return ;
  58.  
  59. }

模拟题,水题。

考虑dogv=0的这种情况。

华中农业大学校赛 I Catching Dogs的更多相关文章

  1. 华中农业大学校赛--c The Same Color

    Problem C: The Same Color Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 993  Solved: 595[Submit][St ...

  2. A喝酒(北京林业大学校赛)

    http://www.jisuanke.com/contest/1410 王大钉喜欢喝酒,存货都喝完了,他就去楼下买,正好楼下的商店为了响应学校的 ACM 校赛推出了优惠活动:凡是在本店买的啤酒,喝完 ...

  3. 北京师范大学校赛C

    https://www.nowcoder.com/acm/contest/submit/0dff89ad7b8444719df155d507f3e1dd?ACMContestId=3&tagI ...

  4. Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)

    Problem H: Heaps Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 48  Solved: 9[Submit][Status][Web Bo ...

  5. 浙江工业大学校赛 小M和天平

    小M和天平 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  6. 浙江工业大学校赛 XiaoWei的战斗力

    XiaoWei的战斗力 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. 浙江工业大学校赛 画图游戏 BugZhu抽抽抽!!

    BugZhu抽抽抽!! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  8. 2016广东工业大学校赛 E题 GDUT-oj1173

    Problem E: 积木积水 Description 现有一堆边长为1的已经放置好的积木,小明(对的,你没看错,的确是陪伴我们成长的那个小明)想知道当下雨天来时会有多少积水.小明又是如此地喜欢二次元 ...

  9. 2016广东工业大学校赛 D题 GDUT-oj1172

    Problem D: 二叉树的中序遍历 Description 对于学过数据结构的人来说,二叉树和二叉树上的中序遍历都是再简单不过的东西了.这道题就搞搞二叉树好了,当然,不是一般的二叉树:) 我们定义 ...

随机推荐

  1. DRP经验总结

    思想 指导 从开始看DRP项目到完成已经有三个月左右的时间了,这是一个足够长的视频,当看第一集的时候就再想,啥时候看完呢? 其间,也断断续续,有时看的效率高有时相反,有时几天看不了几集,好在总算看完了 ...

  2. SQL Server之RAID简介

    一: RAID简介 RAID(Redundant Array of Independent Disk 独立冗余磁盘阵列)是一项数据保护策略. 二: RAID的几种常用级别 1. RAID 0: 通过并 ...

  3. Deep Learning论文笔记之(一)K-means特征学习

    Deep Learning论文笔记之(一)K-means特征学习 zouxy09@qq.com http://blog.csdn.net/zouxy09          自己平时看了一些论文,但老感 ...

  4. jquery ajax方式直接提交整个表单

    $.ajax({ type: "POST", url: url, data: $('#form1').serialize(), success: function(msg){ al ...

  5. Sqlite数据库字符串处理函数replace

    Sqlite 字符串处理函数replace官方说明: replace(X,Y,Z) The replace(X,Y,Z) function returns a string formed by sub ...

  6. 【论文笔记】Leveraging Datasets with Varying Annotations for Face Alignment via Deep Regression Network

    參考文献: Zhang J, Kan M, Shan S, et al. Leveraging Datasets With Varying Annotations for Face Alignment ...

  7. html中嵌入flvplayer.swf播放器,播放视频

    只需要改动红色的代码: <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-4445535411111' codebase='http://downlo ...

  8. laravel 安装环境安了三天!!

    各种报错,各种升级,各种重装,重启!! 记录一下一些错误吧,,, 错误太复杂,,,, 原因:版本问题!.CPU虚拟化问题.win10问题.软件兼容性问题.还有就是各种不细心啥的         分割线 ...

  9. excel 根据单元格内容自动调整列宽

      excel 根据单元格内容自动调整列宽 CreateTime--2018年5月28日08:49:40 Author:Marydon 1.情景展示 单元格宽度超过了列宽 2.解决方案 第一步:同时选 ...

  10. 【Redis】windows环境下安装redis服务器,并配置php的redis扩展

    win7示例: 1.下载Redis服务器 : https://github.com/dmajkic/redis/downloads:(随便下,建议不要太老的) 2.在D:\phpStudy\ 新建Re ...