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[];
double cal(double v,double dogv)
{
if(v>&&dogv>)
{
if(v>dogv) return v-dogv;
else return ;
}
if(v<&&dogv<)
{
if(v<dogv) return dogv-v;
else return ;
}
if(v*dogv<=) return fabs(v+0.0)+fabs(dogv);
}
int main()
{
int n;
double v;
while(scanf("%d%lf",&n,&v)!=EOF)
{
if(n<=) continue;
for(int i=;i<n;i++)
{
scanf("%lf%lf",&dog[i].pos,&dog[i].v);
}
double nt=;
double ans=;
double posp=;
bool flag=true;
for(int i=;i<n;i++)
{ dog[i].pos=dog[i].pos+(dog[i].v*ans);
if(fabs(posp-dog[i].pos)<1e-) 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==) {printf("Bad Dog\n");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\n",ans);
}
return ; }

模拟题,水题。

考虑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. HTML5 input file控件使用accept过滤限制的文件类型以及在谷歌下打开很慢的问题

    在文件上传控件(input type='file')中,可以通过accept属性实现对文件类型的过滤. 一.相关代码: 下面给出对应的文件上传控件代码: <input type="fi ...

  2. qt study 泛型和容器

    所谓泛型(generic) 能够像操作基本类型一样轻松操作对象的类和函数. qt容器类就是泛型类,基于模板的泛型类. 重载运算符overloaed operator, 托管容器 managed con ...

  3. [Python爬虫] 之四:Selenium 抓取微博数据

    抓取代码: # coding=utf-8import osimport refrom selenium import webdriverimport selenium.webdriver.suppor ...

  4. 最短路径算法(Dijkstra)

    1.建立矩阵,记录任意两点间的直接距离: 2.两个集合,一个集合记录到每个点的最短路径,一个记录前驱节点: 3.主循环,每次找当前点与其他点的距离,记录下最短距离和前驱节点,然后看看通过前驱节点和最短 ...

  5. C#基础视频教程2 常见数据类型和属性方法

    记住只要掌握常用的几种数据类型即可(比如Single就很少用了,要用浮点数一般就用Double,现在的计算机内存已经大到不需要你去考虑优化什么了) 比如仅仅是整形就有9种,实际上我们只需要知道int和 ...

  6. NET Framework安装失败的麻烦

    本人机子环境是安装了VS2012,即安装了 .NET Framework4.5,现在要安装AutoCAD2013,而安装CAD2013需要安装4.0的Framework,由于本机已有高版本的Frame ...

  7. [置顶] 深入浅出Spring(四) Spring实例分析

    上次的博文中 深入浅出Spring(二) IoC详解 和 深入浅出Spring(三) AOP详解中,我们分别介绍了一下Spring框架的两个核心一个是IoC,一个是AOP.接下来我们来做一个Sprin ...

  8. Python 整数和浮点数运算

    和数学运算不同的地方是,Python的整数运算结果仍然是整数,浮点数运算结果仍然是浮点数:1 + 2 # ==> 整数 31.0 + 2.0 # ==> 浮点数 3.0 整数和浮点数混合运 ...

  9. MySQL 清理slowlog方法

    MySQL 清理slowlog方法 SET GLOBAL slow_query_log = 'OFF'; ALTER TABLE mysql.slow_log RENAME mysql.slow_lo ...

  10. GNU C中的零长度数组

    http://blog.csdn.net/ssdsafsdsd/article/details/8234736 在标准C和C++中,长度为0的数组是被禁止使用的.不过在GNU C中,存在一个非常奇怪的 ...