华中农业大学c语言程序设计在线作业答案,华中农业大学第四届程序设计大赛网络同步赛 I...

Problem I: Catching Dogs

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 1130  Solved: 292

[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 ithdog 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 ithdog, 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 integers n(n≤10) and v(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

题意:主人抓狗的题目 主人拥有n条狗 主人的速度为v n条狗编号后 有对应的初始位置ai与初始速度vi vi>0代表方向向右

当主人抓到第i只狗后才能抓第i+1只狗 如果能抓到所有的狗输出总时间 否则输出 “Bad Dog”;

题解:模拟 注意精度 double

#include

#include

#include

#include

using namespace std;

double n,v;

struct node

{

double pos;

double v;

}N[];

double init=;

double tim(double target,double vv)

{

double dis,vvv;

if(init>target)

{

dis=init-target;

vvv=v+vv;

}

else

{

dis=target-init;

vvv=v-vv;

}

if(dis==)

return ;

if(vvv<=)

return -;

return dis*1.0/vvv*1.0;

}

int main()

{

while(scanf("%lf %lf",&n,&v)!=EOF)

{

memset(N,,sizeof(N));

int flag=;

for(int i=;i<=n;i++)

scanf("%lf %lf",&N[i].pos,&N[i].v);

double t=,tt=;;

init=;

for(int i=;i<=n;i++)

{

t=tim(N[i].pos+tt*N[i].v,N[i].v);

if(t

{

flag=;

break;

}

if(t>)

tt+=t;

init=N[i].pos+N[i].v*tt;

}

if(flag)

cout<

else

printf("%.2f\n",tt);

}

return ;

}

&lbrack;HZAU&rsqb;华中农业大学第四届程序设计大赛网络同步赛

听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include #include #include ...

&lpar;hzau&rpar;华中农业大学第四届程序设计大赛网络同步赛 G&colon; Array C

题目链接:http://acm.hzau.edu.cn/problem.php?id=18 题意是给你两个长度为n的数组,a数组相当于1到n的物品的数量,b数组相当于物品价值,而真正的价值表示是b[i ...

华中农业大学第四届程序设计大赛网络同步赛 G&period;Array C 线段树或者优先队列

Problem G: Array C Time Limit: 1 Sec  Memory Limit: 128 MB Description Giving two integers  and  and ...

华中农业大学第四届程序设计大赛网络同步赛 J

Problem J: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1766  Solved: 299[Subm ...

华中农业大学第四届程序设计大赛网络同步赛-1020&colon; Arithmetic Sequence,题挺好的,考思路;

1020: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MB Submit:  ->打开链接

华中农业大学第五届程序设计大赛网络同步赛-L

L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...

华中农业大学第五届程序设计大赛网络同步赛-K

K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And ...

华中农业大学第五届程序设计大赛网络同步赛-G

G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

华中农业大学第五届程序设计大赛网络同步赛-D

Problem D: GCD Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 179  Solved: 25[Submit][Status][Web B ...

随机推荐

使用Struts框架,实现用户登陆功能

前言:本篇文章是本人这周学习的一个小结,在自我总结的同时,希望也能够给其他同学带来一点帮助.本文主要知识是参照书本上的知识点以及网上其他博客文章,在上机操练后的所得,具体源码主要来自http://bl ...

在Salesforce中编写Unit Test

Unit Test 也是一个 Class 文件,所以在创建 Unit Test 的时候要选择 Test Class 类型来创建,请看如下截图(在Eclipse中): 编写 Unit Test 基本流程 ...

Linux共享对象之编译参数fPIC

最近在看Linux编程的基础知识,打算对一些比较有趣的知识做一些汇总备忘,本文围绕fPIC展开,学习参考见文末. 在Linux系统中,动态链接文件称为动态共享对象(DSO,Dynamic Shared ...

纯js拖拽参考

function myDrag(obj){ obj.οnmοusedοwn=function(e){ var e=e||window.event; var diffX=e.clientX-this.o ...

mysql连接查询经典小例题

mysql连接查询: Mysql连接查询支持多表连接 对同一张表可以重复连接多次(别名在多次连接同一张表时很重要) 例题1: 下面有2张表 teams表 比赛结果表:result 问题: 得出一张表: ...

带搜索的下拉框Chosen

一:参考 https://harvesthq.github.io/chosen/ Chosen是一个jQuery插件 二:引入js文件

2步安装1个hive docker运行环境&lbrack;centos7&rsqb;

1 构建基础容器 基于centos环境docker环境快速搭建,执行步骤 docker build -t cenosbase7 . 执行此步骤就可以构建1个基础的centos基础运行环境 相关的文件如 ...

性能测试工具 Locust

https://docs.locust.io/en/latest/quickstart.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值