华中农业大学校赛 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 对于学过数据结构的人来说,二叉树和二叉树上的中序遍历都是再简单不过的东西了.这道题就搞搞二叉树好了,当然,不是一般的二叉树:) 我们定义 ...
随机推荐
- Powerdesigner数据库建模--概念模型--ER图
目标: 本文主要介绍PowerDesigner中概念数据模型 CDM的基本概念. 一.概念数据模型概述 数据模型是现实世界中数据特征的抽象.数据模型应该满足三个方面的要求: 1)能够比较真实地模拟现实 ...
- Python mongoHelper模块
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' Defines a MongoOperator class and allows you to m ...
- 对SVM的个人理解---浅显易懂
原文:http://blog.csdn.net/arthur503/article/details/19966891 之前以为SVM很强大很神秘,自己了解了之后发现原理并不难,不过,“大师的功力在于将 ...
- Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能
首先推荐一下鸿洋大大的打造个性的图片预览与多点触控视频教程,这套教程教我们一步一步实现了多点触控实现对图片的平移和缩放的功能.这篇文章我将在鸿洋大大的基础之上做了一些扩展功能: 1.图片的惯性滑动 2 ...
- angularjs中的interval定时执行功能
一个例子,用来显示当前实时时间,1秒钟刷新一次: <!DOCTYPE html> <html ng-app="myApp"> <head> &l ...
- RSA 在C#里简单实现
1.选择两个大素数:p,q;2.计算所得n:n=p*q;3.计算中间结果t:t=(p-1)*(q-1);4.选择一个e:要求e和t的最大公因数是1(也就是e与t互素);5.计算所得d:d*e mod ...
- Reusing dialogs with a dialog pool--一个sql server service broker例子
一个sql server service broker例子 ----------------------------------- USE master GO -------------------- ...
- om.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException
Error:Execution failed for task ':app:dexDebug'.> com.android.ide.common.process.ProcessException ...
- 查看IE浏览器安装的插件
请移步至文章:http://blog.sina.com.cn/u/6452627072
- OFBiz:添加实体栏位
如何添加实体栏位?这里演示为PostalAddress添加planet栏位.打开applications/party/entitydef/entitymodel.xml,找到PostalAddress ...