ELEVSTRS - Editorial

cakewalk
cook85
editorial
elevstrs
math

#1

PROBLEM LINK:

Practice
Contest

Author: Yuri Shilyaev
Tester: Hasan Jaddouh
Editorialist: Yury Shilyaev

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Equation of uniform motion.

PROBLEM:

You are given two variants of route, one with length equal to sqrt(2) * N and maximal velocity V_1, and another with length equal to 2 \cdot N and maximal velocity V_2. You have to find which route will use less time.

QUICK EXPLANATION:

S = v * t, so just calculate time of both routes.
The complexity is O(1) for one testcase, O(T) in total.

EXPLANATION:

Time of the first route is T_1 = \frac{sqrt(2) * N}{ V_1}. Time of the second T_2 = \frac{2 * N}{V_2}.
So, we can compare this fractional numbers, or, alternatively, make some transitions and get that:

T_1 ? T_2

V_2 * sqrt(2) ? V_1 * 2

V_2 ? V_1 * sqrt(2)

So, the first route is faster if V_2 < V_1 * sqrt(2). Why the times couldn’t be equal? Imagine that V_2 = V_1 * sqrt(2). V_2 is integer, while V_1 * sqrt(2) is irrational. Obviously, they can’t be equal.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.

RELATED PROBLEMS:


#2

#include
#include
#include
using namespace std;

int main()
{ int t,n,v1,v2;
string str1=“Elevator”;
string str2=“Stairs”;
cin>>t;
while(t–)
{ cin>>n>>v1>>v2;
if(v2>(v1*sqrt(2)))
cout<<str1<<"
“;
else
cout<<str2<<”
";
}strong text

return 0;

}


#3

//package codechef4;
import java.io.;
import java.util.
;

class Solution {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	
Scanner sc = new Scanner (System.in);

int t = sc.nextInt();
for(int j = 0 ; j < t ; j ++) {
	
	int n = sc.nextInt();
	double v1 = sc.nextDouble();
	double v2 = sc.nextDouble();
	
	double t1=0,t2=0;
	t1 = ((Math.sqrt(2) * n)/v1);
	//System.out.println(t1);
	
	t2 = (2 * n)/v2;
	//System.out.println(t2);
	
	String res = t1 < t2 ? "Stairs" : "Elevator";
	
	System.out.println(res);
	
}

}

}


#4

#include <iostream.h>

using namespace std;
int main()
{
cout<<“hey”;
return 0;
}


#5

Hi

I’m new to code chef recently joined.

I’m trying to solve the elevator problem .Howeve rwhen I submit I keep getting wrong answer error.

Please help!! here’s my code:

int main(){

int distance = 0, vel1 = 0, vel2 = 0; float time1 = 0 ,time2 =0;

//Enter Distance, velocity of elevator and stairs scanf("%d %d %d",&distance,&vel1,&vel2);

/if vel1>vel2 i.e velocity of stairs velocity of Elevator automatically display stairs since 1.41Distance < 2Distance/

if(vel1 >= vel2){
printf(“Stairs”);
return(0); }

time1 = (sqrt(2) * distance)/ (float) vel1; time2 = (2*distance)/(float) vel2; //convert to float

//Check for least time if(time1 <time2)
printf(“Stairs”); else
printf(“Elevator”);

return(0); }