hzauoj Problem I: Catching Dogs (数学模拟)
来源:互联网 发布:约瑟夫问题 c语言 编辑:程序博客网 时间:2024/06/07 03:06
Problem I: Catching Dogs
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 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 1ton. At first Diao Yang is on the original point and his speed isv. Theith dog is on the point ai and its speed isvi. 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)thdog, 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 integersn(n≤10) andv(1≤v≤10). Thenn lines followed, each line contains two integersai(|ai|≤50) andvi(|vi|≤5). vi<0 means the dog runs toward left and vi>0means 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 -32 31 62 -21 10 -11 1-1 -1
Sample Output
6.000.250.00Bad Dog
//:题意:输入n,v,表示有n条狗,小明的速度是v,接下来输入n对数,xi,vi,表示相应的狗的初始位置和速度(vi小于0的话表示狗向左跑,大于0表示向右跑),
小明有n条狗,现在他们都在数轴上以相应速度的相应的方向跑,现在小明想捉住他们,问需要时间是多少?
//思路:
一个一个模拟就行了,没啥说的
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<iostream>#define INF 0x3f3f3f3f#define E 1e-6using namespace std;int main(){int n;double v;while(scanf("%d%lf",&n,&v)!=EOF){double t=0,tt;double x[110],y[110],xx=0; for(int i=0;i<n;i++){scanf("%lf%lf",&x[i],&y[i]);}int flag=0;for(int i=0;i<n;i++){x[i]+=t*y[i];if(x[i]==xx)continue;else{if(y[i]<0){if(xx-x[i]>E){if(fabs(y[i])>=v){flag=1;break;}else{tt=fabs(xx-x[i])/fabs(v+y[i]);t+=tt;xx-=tt*v;}}else{tt=fabs(xx-x[i])/fabs(v-y[i]);t+=tt;xx+=tt*v;}}else{if(xx-x[i]>E){tt=fabs(xx-x[i])/fabs(v+y[i]);t+=tt;xx-=tt*v;}else{if(y[i]>=v){flag=1;break;}else{tt=fabs(xx-x[i])/fabs(v-y[i]);t+=tt;xx+=tt*v;}}}}}if(flag)printf("Bad Dog\n");elseprintf("%.2lf\n",t);}return 0;}
- hzauoj Problem I: Catching Dogs (数学模拟)
- Problem I: Catching Dogs
- Problem I: Catching Dogs
- Problem I: Catching Dogs 几何水题
- 华中农业大学第四届程序设计大赛网络同步赛Problem I: Catching Dogs
- Problem I: Catching Dogs——华中农业大学第四届程序
- HZAU 1018 Catching Dogs
- HZAU--20--Catching Dogs(模拟)
- hzauoj Problem H: Eat Candy (暴力)
- hzauoj Problem J: Arithmetic Sequence (dp)
- hdoj--2522--A simple problem(数学模拟)
- Problem F: 二进制类(1)__运算符重载 hzauoj
- hdoj1032 The 3n + 1 problem (数学模拟)
- Problem D: 二进制类(2)——运算符重载-hzauoj
- Problem I
- Problem I
- Problem I
- Problem I
- AJAX提交页面代码
- Android-BaseAdapter中重写getview的心得以及发现convertView回收的机制
- hadoop2.7.2分布式集群搭建和生态系统配置
- leetcode 191 Number of 1 Bits C++
- idea每次编译设置工程的默认jdk版本1.5问题
- hzauoj Problem I: Catching Dogs (数学模拟)
- JAVA中使用FTPClient实现文件上传下载
- 数据结构,二叉树已知后续中序,建树,层次遍历;
- 【Linux】Shell的变量
- HttpClient
- AsyncTask异步交互机制Demo
- 下拉刷新ListView(二),Pull解析
- DWZ框架tree树形菜单checkbox下取值
- LINUX 使用tcgetattr与tcsetattr函数控制终端