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. create xml file from sql script

    Declare @xmlDoc xmlSET @xmlDoc = (SELECT * FROM USERS AS UserTable For XML AUTO, ELEMENTS, ROOT('Roo ...

  2. [转] windows下sublime2 安装破解(key可用)

    转: http://jingyan.baidu.com/article/ff4116259b057c12e48237b8.html Sublime Text 2安装汉化破解.插件包安装教程 | 浏览: ...

  3. Python requests 报错解决集锦

    python版本号和ssl版本号都会导致 requests在请求https站点时候会出一些错误,最好使用新版本号. 1 Python2.6x use requests 一台老Centos机器上跑着古老 ...

  4. 【转】四大机器学习降维算法:PCA、LDA、LLE、Laplacian Eigenmaps

    最近在找降维的解决方案中,发现了下面的思路,后面可以按照这思路进行尝试下: 链接:http://www.36dsj.com/archives/26723 引言 机器学习领域中所谓的降维就是指采用某种映 ...

  5. 使用ASP.NET上传多个文件到服务器

    在Email系统中经常会上传多个文件到服务器,用户大多习惯一次上传所有的文件,而不是逐个上传,我们可以使用javascript动态地添加file元素到表单,然后在服务器端处理这些file 效果图如下: ...

  6. Oracle的操作系统身份认证

    Oracle的操作系统身份认证 oraclelogin数据库远程登录authenticationos sqlnet.authentication_services=(NTS),在$ORACLE_HOM ...

  7. 通过反射获取class文件中的构造方法,运行构造方法

    /* * 通过反射获取class文件中的构造方法,运行构造方法 * 运行构造方法,创建对象 * 1.获取class文件对象 * 2.从class文件对象中,获取需要的成员 * * Constructo ...

  8. tarjan+缩点+强连通定理

    C - Network of Schools Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I ...

  9. 【linux】查看内存和CPU使用情况

    1.内存命令:free 解释:以上数据单位KB. 所以,上面的mem物理内存共1G 下面是对这些数值的解释: total:总计物理内存的大小. used:已使用多大. free:可用有多少. Shar ...

  10. MySQL-LAST_INSERT_ID();使用注意事项

    第一.查询和插入所使用的Connection对象必须是同一个才可以,否则返回值是不可预料的. mysql> SELECT LAST_INSERT_ID(); -> 100 使 用这函数向一 ...