9BRunning Student

来源:互联网 发布:淘宝旺旺号名字大全 编辑:程序博客网 时间:2024/05/19 03:42

在x轴上坐车,然后在哪个车站,下车,不能在第一个车站下车,要从第二个车站开始计算坐车和跑路花费的总时间,取最小的那个车站。用double定义,用int 定义数据类型,然后*1.0转换小数会莫名出错。。。上代码,有注释。
B. Running Student
time limit per test1 second
memory limit per test64 megabytes
inputstandard input
outputstandard 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.

Examples
input
4 5 2
0 2 4 6
4 1
output
3
input
2 1 1
0 100000
100000 100000
output
2
Note
As you know, students are a special sort of people, and minibuses usually do not hurry. That’s why you should not be surprised, if Student’s speed is higher than the speed of the minibus.

#include<cstdio>#include<cmath>#include<iostream>#include<algorithm>using namespace std;const int N=110;double n,vb,vs,ex,ey;///用 double类型,int 会出错int a[N];double sum(int st){    return st/vb+sqrt((ex-st)*(ex-st)+ey*ey)/vs;  ///求学生坐车和学生跑路花费的时间}int sove(){    int ans=2;    double time=sum(a[2]);  ///第一站不能下车,从第二站开始算,为了方便计算时间,第二站单独算,为后面第三站开始后算时间比较    for(int i=3; i<=n; i++)///遍历第三站开始到大目的地的时间,与上一站时间对比    {        double t=sum(a[i]);        if(t<=time)///等于的含义是在时间相等时,能多坐车就不走路        {            time=t;    ///记录最小时间和车站            ans=i;        }    }    return ans;}int main(){    while(cin>>n>>vb>>vs)    {        for(int i=1; i<=n; i++)            cin>>a[i];        cin>>ex>>ey;        printf("%d\n",sove());    }    return 0;}