Codeforces Beta Round #9 (Div. 2 Only):B
2017-04-12 01:21
218 查看
B. Running Student
time limit per test
1 second
memory limit per test
64 megabytes
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.
Examples
input
output
input
output
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.
题意:一个男孩要去上学,现在有搭车水平行驶以及走路两种方案,或者先搭一段路车后走路。求到达学校所用时间最少。(现在男孩在公交车上,即在第一个站是不能下车的)。
题解:直接暴力枚举在某点下车所用时间,然后更新答案就可以了。
//Wud
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <sstream>
#include <fstream>
#include <set>
#include <map>
#include <string.h>
#define EPS 1e-9
#define M_PI 3.14159265358979323846
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int maxn = 5e6+7;
int n,vb,vs;
int s[150];
int x,y;
int main()
{
while(scanf("%d %d %d",&n,&vb,&vs)!=EOF)
{
for (int i = 0;i < n;i++) scanf("%d",&s[i]);
scanf("%d %d",&x,&y);
double ans = 1e18;
int p;
int clo;
for (int i = 1;i < n;i++)
{
double len = sqrt(1ll*(s[i]-x)*(s[i]-x)+1ll*y*y);
double t = s[i]*1.0/vb+len*1.0/vs;
if(t<ans){
ans = t;
p = i;
clo = abs(s[i]-x);
}
if(t==ans)
{
if(clo>abs(s[i]-x)){
p = i;
clo = abs(s[i]-x);
}
}
}
printf("%d\n",p+1);
}
return 0;
}
time limit per test
1 second
memory limit per test
64 megabytes
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.
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.
题意:一个男孩要去上学,现在有搭车水平行驶以及走路两种方案,或者先搭一段路车后走路。求到达学校所用时间最少。(现在男孩在公交车上,即在第一个站是不能下车的)。
题解:直接暴力枚举在某点下车所用时间,然后更新答案就可以了。
//Wud
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <sstream>
#include <fstream>
#include <set>
#include <map>
#include <string.h>
#define EPS 1e-9
#define M_PI 3.14159265358979323846
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int maxn = 5e6+7;
int n,vb,vs;
int s[150];
int x,y;
int main()
{
while(scanf("%d %d %d",&n,&vb,&vs)!=EOF)
{
for (int i = 0;i < n;i++) scanf("%d",&s[i]);
scanf("%d %d",&x,&y);
double ans = 1e18;
int p;
int clo;
for (int i = 1;i < n;i++)
{
double len = sqrt(1ll*(s[i]-x)*(s[i]-x)+1ll*y*y);
double t = s[i]*1.0/vb+len*1.0/vs;
if(t<ans){
ans = t;
p = i;
clo = abs(s[i]-x);
}
if(t==ans)
{
if(clo>abs(s[i]-x)){
p = i;
clo = abs(s[i]-x);
}
}
}
printf("%d\n",p+1);
}
return 0;
}
相关文章推荐
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新
- Codeforces Beta Round #83 (Div. 1 Only) E.Darts 凸多边形面积交
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- #9 (Div. 2 Only) D. How many trees? (dp)(好题)
- Codeforces Beta Round #74 (Div. 2 Only)——C
- Codeforces Beta Round #4 (Div. 2 Only) B. Before an Exam dp
- Codeforces Beta Round #4 (Div. 2 Only)
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
- Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland
- Codeforces Beta Round #87 (Div. 1 Only)A. Party(深搜/树高)
- CodeForces round 428 div2 only
- Codeforces Beta Round #86 (Div. 2 Only) B PFAST Inc.
- Codeforces Beta Round #83 (Div. 1 Only) E.Darts 凸多边形面积交
- Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array
- Codeforces Beta Round #4 (Div. 2 Only) B. Before an Exam dp
- Codeforces Beta Round #83 (Div. 1 Only)
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- 类似最长递增子序,记忆化DP—— Codeforces Beta Round #4 (Div. 2 Only)D - Mysterious Present
- Codeforces Beta Round #4 (Div. 2 Only)