首页 > 其他 > 详细

CodeForces - 9B - Running Student

时间:2014-02-28 08:40:59      阅读:525      评论:0      收藏:0      [点我收藏+]

先上题目:

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: bubuko.com,布布扣
  • 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: bubuko.com,布布扣
  • 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?≤?1001?≤?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轴上,那么在二号站下车直接步行去学校比在二号站下车然后走回一号站在去学校近(昨晚做的时候脑子短路了→_→)。然后还要注意的是多情况的时候在距离学校最近的巴士站下车,注意了这些地方就没有问题了。

上代码:

bubuko.com,布布扣
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 #include <algorithm>
 5 #define min(x,y) (x < y ? x : y)
 6 #define LL long long
 7 #define INF (1<<30)
 8 #define MAX 102
 9 using namespace std;
10 
11 double dis[MAX];
12 int n;
13 
14 int main()
15 {
16     double vb,vs;
17     double t,t1,d,d1;
18     double a,b;
19     int u;
20     //freopen("data.txt","r",stdin);
21     scanf("%d %lf %lf",&n,&vb,&vs);
22     for(int i=1;i<=n;i++){
23         scanf("%lf",&dis[i]);
24     }
25     d=t=INF;
26     scanf("%lf %lf",&a,&b);
27     for(int i=2;i<=n;i++){
28         d1=sqrt(pow(dis[i]-a,2)+pow(b-0,2));
29         t1=d1/vs+dis[i]/vb;
30         if(t>t1 || (t==t1 && d>d1)){
31             t=t1;
32             d=d1;
33             u=i;
34         }
35     }
36     printf("%d\n",u);
37     return 0;
38 }
9B

 

CodeForces - 9B - Running Student,布布扣,bubuko.com

CodeForces - 9B - Running Student

原文:http://www.cnblogs.com/sineatos/p/3571481.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!