codeforce 9B

本文介绍了一种算法问题,即如何在多个公交站点中选择最优的下车点以便尽快抵达目的地。考虑了公交车与步行的不同速度,并给出了具体的实现代码。

http://vjudge.net/contest/view.action?cid=47681#problem/B

Description

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 ≤ 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 Input

Input
4 5 2
0 2 4 6
4 1
Output
3
Input
2 1 1
0 100000
100000 100000
Output
2

Hint

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.

题目大意:在平面直角坐标系中有一点(x,y)从(0,0)出发到该点去,其中在x轴上有一些公交站,可以再00到任意一站之间坐公交,下了站后必须步行到达终点。公交速度和步行速度已给出,求经过几个站后下车,用时最小。第一站为(0,0,)不可下车,若有相同的时间,取距离终点最近的车站下车

纯水题,要注意在double和double比较上的处理,不能用等号。

#include <stdio.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
double mm(double  x,double y,double a,double b)
{
    return sqrt((x-a)*(x-a)+(y-b)*(y-b));
}
int abs(int x,int y)
{
    if(x>y)
        return x-y;
    return y-x;
}
double a[1005];
double b[1005];
int main()
{
    int n,m,k,x,y;
    while(~scanf("%d%d%d",&k,&n,&m))
    {
        for(int i=0;i<k;i++)
        {
            scanf("%lf",&a[i]);
        }
        scanf("%d%d",&x,&y);
        double minn=999999999;
        for(int i=1;i<k;i++)
        {
            b[i]=(mm(x,y,a[i],0)*1.0/m+a[i]*1.0/n);
            minn=min(b[i],minn);
        }
        int mxxx=99999999;
        for(int i=1;i<k;i++)
             if(fabs(minn-b[i])<1e-10&&abs(i,x)<mxxx)
                mxxx=i;
        printf("%d\n",mxxx+1);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值