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. poj2142 The Balance 扩展欧几里德的应用 稍微还是有点难度的

    题目意思一开始没理解,原来是 给你重为a,b,的砝码 求测出 重量为d的砝码,a,b砝码可以无限量使用 开始时我列出来三个方程 : a*x+b*y=d; a*x-b*y=d; b*y-ax=d; 傻眼 ...

  2. Resin install document

    Centos6快速安装文档 resin3.1.13 软件下载地址: http://caucho.com/products/resin/download/gpl#download #系统环境[root@ ...

  3. kubernetes基础概念

    kubernetes是基于容器技术的分布式架构领先方案.具有完备的集群管理能力,包括多层次的安全防护和准入机制.多租户应用支撑能力.透明的服务注册和服务发现机制.内建智能负载均衡器.强大的故障发现和自 ...

  4. SQL insert失败时也会造成自增长字段加1

    CREATE TABLE #test(id INT IDENTITY(1,1), NAME varchar(30)) INSERT #test(name)SELECT '41545' SELECT   ...

  5. Java GC、新生代、老年代

    堆内存 Java 中的堆是 JVM 所管理的最大的一块内存空间,主要用于存放各种类的实例对象.在 Java 中,堆被划分成两个不同的区域:新生代 ( Young ).老年代 ( Old ).新生代 ( ...

  6. 【React】初识React

    React是什么 React是如今(2015年)最热门的前端技术. 在React中.一切皆组件. A JavaScript library for building user interfaces R ...

  7. 使用Nodejs的Nodemailer通过163信箱发送邮件例程

    首先需要安装一下nodemailer #nmp nodemailer install --save 然后就参照官方文档的例程改写一下就行了,代码如下: 'use strict'; const node ...

  8. 理解 select poll epoll

    举例说明:老师收学生作业,相当于应用层调用I/O操作. 1.老师逐个收学生作业,学生没有做完,只能阻塞等待,收了之后,再去收下一个学生的作业.这显然存在性能问题. 2.怎么解决上面的问题? 老师找个班 ...

  9. C++ 中特殊的用法

    1.反斜杠 a.转义字符 b.强制换行,当一行代码很长时,在这一行中间加上反斜杠,分成两行,反斜杠前后不能有空格.在预编译的的时候,会合成一行. 2.String^ 表明String是一个托管类型的指 ...

  10. Spring Boot学习记录(二)–thymeleaf模板

    自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...