枚举——Running Student

Running Student

题面翻译

题目描述

一位可怜的学生再次遭遇不幸——他要考试迟到了。

【他所在的地区可以看成一个平面直角坐标系,】他跑到了位于(0,0)处的公交车站,上了一辆小巴。这辆小巴沿x轴向x轴正方向行驶。

这个学生知道这样一些事:

这辆小巴将停靠n个站点,其中第i个站点位于(xi,0)处。

每一个站点的坐标都不相同。

这辆小巴将以速度vb匀速行驶。

小巴停站的时间很短,可以忽略不计。

乘客只能在站点上下车。

乘客最晚必须在终点站下车。

考试地点在(xu,yu)处。

他可以用vs的速度匀速从一个车站跑向考试地点。

在平面直角坐标系内,两点间的距离可以用表示

他不能在上车站下车。
这个可怜的学生想用尽可能短的时间到达考试地点。请你帮他选择一个可以达到他的目的的下车地点。如果有多个满足的下车地点,请输出离考试地点最近的一个。

输入输出格式

输入格式

输入的第一行包括三个整数:n,vb和vs。第二行包括n个升序排序的非负整数,第i个数表示第i个站点的横坐标。第1个数一定等于0。第三行包括两个整数,依次为考试地点的横坐标xu和纵坐标yu。

输出格式

输出一行,一个整数,他应该下车站的序号。

说明

数据范围

保证2<=n<=100,1<=vb,vs<=1000,0<=xi<=105,0<=|xu|,|yu|<=105

其他

就像你所知道的一样,学生通常是匆匆忙忙的,但小巴通常不是。所以如果你发现学生的速度比小巴快,不要吃惊。

题目描述

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 $ (x_{i},0) $
  • coordinates of all the stops are different
  • the minibus drives at a constant speed, equal to $ v_{b} $
  • 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 $ (x_{u},y_{u}) $
  • Student can run from a bus stop to the University at a constant speed $ v_{s} $ 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<=v_{b},v_{s}<=1000 $ . The second line contains $ n $ non-negative integers in ascending order: coordinates $ x_{i} $ of the bus stop with index $ i $ . It is guaranteed that $ x_{1} $ equals to zero, and $ x_{n}<=10^{5} $ . The third line contains the coordinates of the University, integers $ x_{u} $ and $ y_{u} $ , not exceeding $ 10^{5} $ in absolute value.

输出格式

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

样例 #1

样例输入 #1

4 5 2
0 2 4 6
4 1

样例输出 #1

3

样例 #2

样例输入 #2

2 1 1
0 100000
100000 100000

样例输出 #2

2

提示

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<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

const int N = 1e5+10;

int n;
double vb,vs;
double w[N];
double st,ed;
double minv1=2e18,minv2=2e18;
//minv1表示的是总距离,minv2表示的是距离考试节点的距离

double dist(double a,double b){
    double x=a-b;
    double y=ed;
    return sqrt(x*x+y*y);
}

int main(){
    cin>>n>>vb>>vs;
    
    for(int i=1;i<=n;i++){
        cin>>w[i];
    }
    cin>>st>>ed;
    
    //麻烦了
    
    // for(int i=1;i<=n;i++){
    //     a[i]={abs(w[i]-st),i};
    // }
    
    // sort(a+1,a+1+n);
    
    // double minv=w[a[1].y]*vb+dist(st,a[1].x)/vs*1.0;
    // int ans=a[1].y;
    int ans=-1;
    for(int i=2;i<=n;i++){
        double a=w[i]/vb;
        double b=dist(st,w[i])/vs;
        if(b+a<=minv1&&b<minv2){
            minv1=a+b;
            minv2=b;
            ans=i;
        }
    }
    
    cout<<ans;
    
    return 0;
}
  • 29
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

green qwq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值