华中农业大学校赛 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 对于学过数据结构的人来说,二叉树和二叉树上的中序遍历都是再简单不过的东西了.这道题就搞搞二叉树好了,当然,不是一般的二叉树:) 我们定义 ...
随机推荐
- Windows2003 Webshell默认权限
0×00 前言 0×01 Windows2003默认配置 0×02 Windows2003典型配置的权限 0×03 cmd运行的条件 0×00 前言 这一章主要讲解关于我们刚拿到webshell的 ...
- DRP经验总结
思想 指导 从开始看DRP项目到完成已经有三个月左右的时间了,这是一个足够长的视频,当看第一集的时候就再想,啥时候看完呢? 其间,也断断续续,有时看的效率高有时相反,有时几天看不了几集,好在总算看完了 ...
- 如何通过.reg文件来修改注册表键和子键以及键值
无废话, 直接上例子, 自己运行一下便知. 然后根据自己需要改改就可以随便用了. 添加key, subkey, 和设置键值的例子. ==================== Windows Reg ...
- Linux中的In命令
ln是linux中一个非常重要命令.它的功能是为某一个文件在另外一个位置建立一个同步的链接,这个命令最常用的参数是-s,具体用法是: ln -s 源文件 目标文件 -s 是 symbolic的 ...
- Python socket – network programming tutorial
原文:https://www.binarytides.com/python-socket-programming-tutorial/ --------------------------------- ...
- Kettle中txt类型数据源作为输入需要注意的地方
文本类型在kettle中作为数据源的时候,需要注意的几点,ktr的机构如下图 1:txt文本的格式 2:文本输入控件的设置 --2.1:选择文件所在物理位置 --2.2:设置分隔符,注意头部数量去掉, ...
- 用CSS下划线距离
但在我在CSS中新加了TEXT-DECORATION: underline; 后发现下划线离文本太近了,很难看. 代码一: a { text-decoration: none; background: ...
- (剑指Offer)面试题6:重建二叉树
题目: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树. 假设输入的前序遍历和中序遍历结果中都不含重复的数字. 例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...
- 【转载】AngularJS监听路由变化
一.Angular 路由状态发生改变时可以通过' $stateChangeStart '.' $stateChangeSuccess '.' $stateChangeError '监听,通过注入'$l ...
- IDEA20181.4破解
1.下载破解补丁: http://idea.lanyus.com/jar/JetbrainsIdesCrack-4.2-release-sha1-3323d5d0b82e716609808090d3d ...