CodeForces - 9B - Running Student
先上题目:
1 second
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.
standard input
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.
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.
In the only line output the answer to the problem — index of the optimum bus stop.
4 5 2
0 2 4 6
4 1
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的更多相关文章
- 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 ...
- Codeforces 615C Running Track(DP + Trie树)
题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...
- CodeForces 605B Lazy Student
构造.对边的权值排序,权值一样的话,在MST中的边排到前面,否则权值小的排在前面. 然后边一条一条扫过去,如果是1 ,那么连一个点到集合中,如果是0,集合内的边相连. #include<cstd ...
- 【CodeForces】9B-Running Student
目录 Question Description Input Output Solution 解法1 Question Description 小明在公交车始发站上车,他应该在哪个站点下车才能最快到达学 ...
- Codeforces 1244G. Running in Pairs
传送门 首先对于两个排列 $A,B$ 我们可以把 $A$ 从小到大排序并把 $B$ 重新和 $A$ 一一对应 显然这样不会影响 $\sum_{i=1}^{n}max(A_i,B_i)$ 的值 所以直接 ...
- JavaScript 继承的几种模式
/** * Created by 2016 on 2016/6/5. */ //1.原型链继承 //把子类的原型,定义为超类的实例 通过原型来访问超类的方法和属性 function Person(){ ...
- RH033读书笔记(16)-Lab 17 Installation and Administration Tools
Lab 17 Installation and Administration Tools Goal: Become familiar with system configuration tools a ...
- 廖雪峰Java2面向对象编程-3继承和多态-2多态
1.重载 子类覆写父类的方法称为重载Override. 父类和子类拥有一摸一样的方法(方法的名字.返回值.参数是相同的,但是方法的语句是不一样的) 方法签名如果不同就不是重载,而是创建了一个新的方法. ...
- 廖雪峰Java2面向对象编程-3继承和多态-1继承
1.继承 继承是一种代码复用的方式. Student与Person有相同部分的代码. Student可以从Person继承,这样Student获得了Person的所有功能,只需要编写新增的功能即可.通 ...
随机推荐
- Java-MyBatis:MyBatis
ylbtech-Java-MyBatis:MyBatis 1.返回顶部 1. MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foun ...
- 3Ddungeon-------三维搜索-----偷个懒 把 亡命逃窜 的代码修改了一下 拿来用了
题 很简单 就是给一个 三维的迷宫然后 开你起始地点 S 问你能不能到达 出口 E 能的话 需要多长时间 ? #include<stdio.h> #include<string ...
- B - Eleven
Problem description Eleven wants to choose a new name for herself. As a bunch of geeks, her friends ...
- Spark Streaming概述
Spark Streaming是一种构建在Spark上的实时计算框架,它扩展了Spark处理大规模流式数据的能力. 其中包括:资源管理框架,Apache YARN.Apache Mesos:基于内存的 ...
- js基础---字符串方法
// var str1="xudandan"; // 字符串长度 var str1_length=str1.length;console.log(str1);console.log ...
- matplotlib之pyplot 学习示例
现在通过numpy和matplotlib.pyplot 在Python上实现科学计算和绘图,而且和matlab极为相像(效率差点,关键是方便简单) 这里有大量plots代码例子. 1. 简单的绘图( ...
- Django学习案例一(blog):三. 模型生成数据
1. 什么是模型models Django中以创建类的形式来创建数据表. 在编写代码的过程中,所有对数据库的操作,都是对类和类的对象进行操作. ORM对象关系映射(Object relation ma ...
- ie8及其以下版本兼容性问题之文本省略
1. 单行文本省略 单行文本省略适用于文本超出内容显示区,则在末尾显示省略号 1.1 普通文本超出省略 普通文本超出显示省略号,示例: .p{ height: 30px line-height: 30 ...
- Android上UDP组播无法接收数据的问题
最近,想做一个跨平台的局域网的文件传输软件,思路是组播设备信息,TCP连接传输文件.于是进行了一次简单的UDP组播测试,发现Android对于UDP组播接收数据的支持即极为有限. 部分代码如下 pac ...
- Linux通信之poll机制分析
poll机制分析 韦东山 2009.12.10 所有的系统调用,基于都可以在它的名字前加上“sys_”前缀,这就是它在内核中对应的函数.比如系统调用open.read.write.poll,与之对应的 ...