×

# ELEVSTRS - Editorial

Author: Yuri Shilyaev
Editorialist: Yury Shilyaev

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:

This question is marked "community wiki".

119
accept rate: 0%

19.8k350498541

# include<string>

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<<"\n"; else cout<<str2<<"\n"; }strong text

return 0;

}

1
accept rate: 0%

 0 //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); } } } answered 29 Aug '17, 00:09 1 accept rate: 0%

# include <iostream.h>

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

1
accept rate: 0%

 0 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
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,679
×1,652
×877
×31
×12

question asked: 20 Aug '17, 18:22

question was seen: 1,480 times

last updated: 20 Feb '18, 15:55