先上题目:

B. Running Student
time limit per test

1 second

memory limit per test

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.

input

standard input

output

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.

Input

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.

Output

In the only line output the answer to the problem — index of the optimum bus stop.

Sample test(s)
input
4 5 2
0 2 4 6
4 1
output
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的更多相关文章

  1. 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 ...

  2. Codeforces 615C Running Track(DP + Trie树)

    题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...

  3. CodeForces 605B Lazy Student

    构造.对边的权值排序,权值一样的话,在MST中的边排到前面,否则权值小的排在前面. 然后边一条一条扫过去,如果是1 ,那么连一个点到集合中,如果是0,集合内的边相连. #include<cstd ...

  4. 【CodeForces】9B-Running Student

    目录 Question Description Input Output Solution 解法1 Question Description 小明在公交车始发站上车,他应该在哪个站点下车才能最快到达学 ...

  5. Codeforces 1244G. Running in Pairs

    传送门 首先对于两个排列 $A,B$ 我们可以把 $A$ 从小到大排序并把 $B$ 重新和 $A$ 一一对应 显然这样不会影响 $\sum_{i=1}^{n}max(A_i,B_i)$ 的值 所以直接 ...

  6. JavaScript 继承的几种模式

    /** * Created by 2016 on 2016/6/5. */ //1.原型链继承 //把子类的原型,定义为超类的实例 通过原型来访问超类的方法和属性 function Person(){ ...

  7. RH033读书笔记(16)-Lab 17 Installation and Administration Tools

    Lab 17 Installation and Administration Tools Goal: Become familiar with system configuration tools a ...

  8. 廖雪峰Java2面向对象编程-3继承和多态-2多态

    1.重载 子类覆写父类的方法称为重载Override. 父类和子类拥有一摸一样的方法(方法的名字.返回值.参数是相同的,但是方法的语句是不一样的) 方法签名如果不同就不是重载,而是创建了一个新的方法. ...

  9. 廖雪峰Java2面向对象编程-3继承和多态-1继承

    1.继承 继承是一种代码复用的方式. Student与Person有相同部分的代码. Student可以从Person继承,这样Student获得了Person的所有功能,只需要编写新增的功能即可.通 ...

随机推荐

  1. etcd数据备份与恢复验证

    一.单机 说明:执行etcd备份数据的恢复的机器必须和原先etcd所在机器一致 1.单机备份 etcdctl --endpoints="https://10.25.72.62:2379&qu ...

  2. netty百万连接跟踪记录

    0. 启动客户端和服务端 # 测试环境: centos7 jdk8 2核16G# 服务端启动nohup java -Xmx8192m -Xms4096m -XX:+UseG1GC -XX:Parall ...

  3. mac下配置nginx

    nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,下面我们来了解下nginx的用法. 安装nginx 使用brew安装nginx brew install ...

  4. 开启远程MySQL

    安装完MySQL,由于安全原因默认是没有赋予用户远程权限的,所以第一步要首先赋予用户对应的权限 一  授权 mysql> mysql -u用户名 [-pIp地址] -p #登录 mysql> ...

  5. ViewPager PagerAdapter 的使用

    1: 目的,实现全屏滑动的效果 2:类似于BaseAdapter public class MyPagerAdapter extends PagerAdapter { private Context ...

  6. 打包Python程序

    我选择的是pyinstaller,(py2exe到目前为止只支持到Python3.4). 安装.如果能联网最后用pip.在cmd中输入pip install Pyinstaller.如果不能联网,可以 ...

  7. MxNet : use the MxNet windows versioin

    The MxNet needs  the following thirdparties: 1. lapack complie lapack-3.6.1: download the lapack-3.6 ...

  8. OpenCV : 基于切线方向的边缘增强算法

    使用切线方法,对切线方向上的边缘进行强化: 参考连接:图像锐化和边缘检测 代码: //在种子点方向上寻找合适的梯度,用于寻找边缘 //对low_Gray, high_gray之间的点寻找边缘 void ...

  9. 设计包含min()函数的栈

    题目:定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素.要求函数min.push以及pop的时间复杂度都是O(1). 分析:这是去年google的一道面试题. 我看到这道题目时,第一反应 ...

  10. Linux下Shell脚本输出带颜色文字

    文本终端的颜色可以使用“ANSI非常规字符序列”来生成.举例: echo -e "\033[44;37;5m ME \033[0m COOL" 以上命令设置作用如下: 背景色为蓝色 ...