华中农业大学校赛 I Catching Dogs
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的更多相关文章
- 华中农业大学校赛--c The Same Color
Problem C: The Same Color Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 993 Solved: 595[Submit][St ...
- A喝酒(北京林业大学校赛)
http://www.jisuanke.com/contest/1410 王大钉喜欢喝酒,存货都喝完了,他就去楼下买,正好楼下的商店为了响应学校的 ACM 校赛推出了优惠活动:凡是在本店买的啤酒,喝完 ...
- 北京师范大学校赛C
https://www.nowcoder.com/acm/contest/submit/0dff89ad7b8444719df155d507f3e1dd?ACMContestId=3&tagI ...
- 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 ...
- 浙江工业大学校赛 小M和天平
小M和天平 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- 浙江工业大学校赛 XiaoWei的战斗力
XiaoWei的战斗力 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 浙江工业大学校赛 画图游戏 BugZhu抽抽抽!!
BugZhu抽抽抽!! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 2016广东工业大学校赛 E题 GDUT-oj1173
Problem E: 积木积水 Description 现有一堆边长为1的已经放置好的积木,小明(对的,你没看错,的确是陪伴我们成长的那个小明)想知道当下雨天来时会有多少积水.小明又是如此地喜欢二次元 ...
- 2016广东工业大学校赛 D题 GDUT-oj1172
Problem D: 二叉树的中序遍历 Description 对于学过数据结构的人来说,二叉树和二叉树上的中序遍历都是再简单不过的东西了.这道题就搞搞二叉树好了,当然,不是一般的二叉树:) 我们定义 ...
随机推荐
- Linux 网络设备驱动开发(一) —— linux内核网络分层结构
Preface Linux内核对网络驱动程序使用统一的接口,并且对于网络设备采用面向对象的思想设计. Linux内核采用分层结构处理网络数据包.分层结构与网络协议的结构匹配,既能简化数据包处理流程,又 ...
- HTML5/CSS3实现添加锁屏效果
锁屏效果,也就是将屏幕置于模态,不允许用户触发任何动作,只能解除锁定后才能继续使用,jQueryUI的dialog有模态对话框,这一点不难做到.那么,首先需要在页面中添加一个div层,用于做模态的层 ...
- Web开发中的6个坏习惯
在 Usersnap,我们在能很好的组织网站开发有超过20(总和)年的经验.我们认为这些过去的经验能让我们很好的分辨出什么是好.坏和丑陋的网站开发.如今我们不想把注意力放在消极的部分,但就这一次,我们 ...
- Linux 查看当前时间和修改系统时间
一.查看和修改Linux的时区 1. 查看当前时区 命令: date -R 2. 修改设置Linux服务器时区 方法 A 命令 : tzselect 方法 B 仅限于RedHat Linux 和 Ce ...
- java设计模式0--设计模式简介
设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 设计模式的起源 软件 ...
- Android -- 消息处理机制源码分析(Looper,Handler,Message)
android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个Message Queue(消息队列),但是MQ被封装到Looper里面了,我们不会直接与MQ打交道,因 ...
- es6中的import,export浏览器已经支持
直接上代码, 成功测验了es6的新特性 import , export语法. 服务器返回 js文件时,要加上content-type: applicaiton/javascript 这个字段. ind ...
- 成都PHP开发project师薪资信息
这是成都的PHPproject开发师招聘.如图所见,最低的月薪是4K,最高的是35W,PHP开发工程师正处于炙手可热的发展趋势,还愁拿不到高薪,找不到工作的你,还犹豫什么,机会就在眼前,成都传智播客P ...
- Android中的一些小技巧
这个是App判断是pad还是手机的代码: public boolean isTabletDevice() { TelephonyManager telephony = (TelephonyManage ...
- java Socket通信使用BufferedReader和BufferedWriter的注意事项
注意事项:readLine()要求有换行标识,write()要输出换行标识,要调用flush()刷新缓冲区. 以下是取自java socket通信中的一小段代码. BufferedReader rea ...