先上题目:

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. 10g异机恢复后EM无法启动故障处理一例

    之前在自己的測试环境上做了个异机恢复,原来的库上是配置过EM的,可是在恢复的库上去启动EM就报错了.以下看详细解决过程: PS:原主机名为zlm,恢复出来的主机名为bak [root@bak ~]# ...

  2. linux中的alsa工具与Android中的tinyalsa工具【转】

    本文转载自:http://blog.csdn.net/luckywang1103/article/details/48053015 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?) ...

  3. 84. ExtJS下页面显示中文乱码问题

    转自:https://blog.csdn.net/wenminhao/article/details/51198981 最近在学校extjs是,使用js脚本显示中文在html页面中时,中午出现了乱码的 ...

  4. 树莓派(raspberry)启用root账户

    树莓派使用的linux是debian系统,所以树莓派启用root和debian是相同的. debian里root账户默认没有密码,但账户锁定. 当需要root权限时,由默认账户经由sudo执行,Ras ...

  5. Blue Jeans(串)

    http://poj.org/problem?id=3080 寻找最长公共子串..暴搜的.. #include<stdio.h> #include<string.h> int ...

  6. 关于我们ajax异步请求的方法与知识

      做前端开发的朋友对于ajax异步更新一定印象深刻,作为刚入坑的小白,今天就和大家一起聊聊关于ajax异步请求的那点事.既然是ajax就少不了jQuery的知识,推荐大家访问www.w3school ...

  7. Java.HttpClient绕过Https证书解决方案一

    方案1 import javax.net.ssl.*; import java.io.*; import java.net.URL; import java.security.KeyManagemen ...

  8. E - A Trivial Problem(求满足x!的尾数恰好有m个0的所有x)

    Problem description Mr. Santa asks all the great programmers of the world to solve a trivial problem ...

  9. B - Is your horseshoe on the other hoof?

    Problem description Valera the Horse is going to the party with friends. He has been following the f ...

  10. dom转换成jquery对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...