CodeForces - 9B - Running Student
先上题目:
1 second
64 megabytes
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
- during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
- coordinates of all the stops are different
- the minibus drives at a constant speed, equal to vb
- it can be assumed the passengers get on and off the minibus at a bus stop momentarily
- Student can get off the minibus only at a bus stop
- Student will have to get off the minibus at a terminal stop, if he does not get off earlier
- the University, where the exam will be held, is in point (xu, yu)
- Student can run from a bus stop to the University at a constant speed vs as long as needed
- a distance between two points can be calculated according to the following formula:

- Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
standard input
standard output
And again a misfortune fell on Poor Student. He is being late for an exam.
Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.
Poor Student knows the following:
- during one run the minibus makes n stops, the i-th stop is in point (xi, 0)
- coordinates of all the stops are different
- the minibus drives at a constant speed, equal to vb
- it can be assumed the passengers get on and off the minibus at a bus stop momentarily
- Student can get off the minibus only at a bus stop
- Student will have to get off the minibus at a terminal stop, if he does not get off earlier
- the University, where the exam will be held, is in point (xu, yu)
- Student can run from a bus stop to the University at a constant speed vs as long as needed
- a distance between two points can be calculated according to the following formula:

- Student is already on the minibus, so, he cannot get off at the first bus stop
Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.
The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.
In the only line output the answer to the problem — index of the optimum bus stop.
4 5 2
0 2 4 6
4 1
3 题意:学生从(0,0)出发,X轴上面有一系列的巴士站,(x,y)代表学校位置,给出巴士速度和学生步行速度,现在学生已在(0,0)上车,车已开动,问学生在哪个巴士站下车才能最早到达学校,如果有多种情况,在距离学校最近的巴士站下车。
其实这题很简单,只是一开始想的时候想复杂了写成dij了→_→,如果学校就在Y轴上,那么在二号站下车直接步行去学校比在二号站下车然后走回一号站在去学校近(昨晚做的时候脑子短路了→_→)。然后还要注意的是多情况的时候在距离学校最近的巴士站下车,注意了这些地方就没有问题了。 上代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define min(x,y) (x < y ? x : y)
#define LL long long
#define INF (1<<30)
#define MAX 102
using namespace std; double dis[MAX];
int n; int main()
{
double vb,vs;
double t,t1,d,d1;
double a,b;
int u;
//freopen("data.txt","r",stdin);
scanf("%d %lf %lf",&n,&vb,&vs);
for(int i=;i<=n;i++){
scanf("%lf",&dis[i]);
}
d=t=INF;
scanf("%lf %lf",&a,&b);
for(int i=;i<=n;i++){
d1=sqrt(pow(dis[i]-a,)+pow(b-,));
t1=d1/vs+dis[i]/vb;
if(t>t1 || (t==t1 && d>d1)){
t=t1;
d=d1;
u=i;
}
}
printf("%d\n",u);
return ;
}
9B
CodeForces - 9B - Running Student的更多相关文章
- Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题
B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...
- Codeforces 615C Running Track(DP + Trie树)
题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...
- CodeForces 605B Lazy Student
构造.对边的权值排序,权值一样的话,在MST中的边排到前面,否则权值小的排在前面. 然后边一条一条扫过去,如果是1 ,那么连一个点到集合中,如果是0,集合内的边相连. #include<cstd ...
- 【CodeForces】9B-Running Student
目录 Question Description Input Output Solution 解法1 Question Description 小明在公交车始发站上车,他应该在哪个站点下车才能最快到达学 ...
- Codeforces 1244G. Running in Pairs
传送门 首先对于两个排列 $A,B$ 我们可以把 $A$ 从小到大排序并把 $B$ 重新和 $A$ 一一对应 显然这样不会影响 $\sum_{i=1}^{n}max(A_i,B_i)$ 的值 所以直接 ...
- JavaScript 继承的几种模式
/** * Created by 2016 on 2016/6/5. */ //1.原型链继承 //把子类的原型,定义为超类的实例 通过原型来访问超类的方法和属性 function Person(){ ...
- RH033读书笔记(16)-Lab 17 Installation and Administration Tools
Lab 17 Installation and Administration Tools Goal: Become familiar with system configuration tools a ...
- 廖雪峰Java2面向对象编程-3继承和多态-2多态
1.重载 子类覆写父类的方法称为重载Override. 父类和子类拥有一摸一样的方法(方法的名字.返回值.参数是相同的,但是方法的语句是不一样的) 方法签名如果不同就不是重载,而是创建了一个新的方法. ...
- 廖雪峰Java2面向对象编程-3继承和多态-1继承
1.继承 继承是一种代码复用的方式. Student与Person有相同部分的代码. Student可以从Person继承,这样Student获得了Person的所有功能,只需要编写新增的功能即可.通 ...
随机推荐
- luogu2746 校园网
题目大意: 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要 ...
- oc53--autorelease注意事项
// // main.m // autorelease注意事项 #import <Foundation/Foundation.h> #import "Person.h" ...
- ubuntu 关机命令
ubuntu 关机命令 关机命令 shutdown ubuntu的终端中默认的是当前用户的命令,只是普通用户,因此在终端器中可以使用sudo -sh 转换到管理员root用户下执行命令. 1)shut ...
- C# 文件的一些基本操作(转)//用C#读写ini配置文件
C# 文件的一些基本操作 2009-07-19 来自:博客园 字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...
- 第11课 Git GUI程序的基本功能
11-1 Git GUI程序的基本操作
- 想要学好C/C++,我到底要看多少书才能成为一个合格的C/C++工程师?
如何学好C语言 这可能是很多朋友的问题,我以前也有这样的感觉,编程编到一定的时候,发现能力到了瓶颈,既不深,也不扎实,半吊子.比如:你长期地使用Java和.NET ,这些有虚拟机的语言对于开发便利是便 ...
- C# 处理oralce 时间
addWorkSql.Append("to_date(' " + DateTime.Now.ToString("yyyy-MM-dd HH:ss:mm") + ...
- MyBatis动态条件、一对多、整合spring(二)
输入映射和输出映射 Mapper.xml映射文件定义了操作数据库的sql,每一个sql是一个statement,映射文件是mybatis的核心. parameterType输入类型 1.传递简单类型 ...
- MVC微信浏览器图片上传(img转Base64)
因公司业务需要,需要做一个微信公众号里的图片上传功能,主要用到的技术就是 img转base64 上到服务器 话不多说, 贴代码 先看前端显示出来的东西 OK 图片不重要,看代码 <!--微信图片 ...
- 【Arduino】LCD 1602 转接板 的默认接线
原来的1602屏需要7个IO口才能驱动起来LCD 1602转接板可以帮你省5个IO口. 在Arduino中,LCD 1602 转接板可以使用函数库LiquidCrystal_I2C1602: 该函数的 ...