Created
April 12, 2020 20:51
-
-
Save shcyiza/17f0c96b6c43b9594e079df82e006cec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
const speed = parseInt(readline()); | |
const lightCount = parseInt(readline()); | |
const lights_data = []; | |
const getSpeedInKmH = (dist, dur) => Math.floor( | |
dist / (dur /3.6) | |
); | |
for (let i = 0; i < lightCount; i++) { | |
var inputs = readline().split(' '); | |
const current = {} | |
current.dist = parseInt(inputs[0]); | |
current.dur = parseInt(inputs[1]); | |
lights_data.push(current); | |
} | |
function passesAtGreen(light, km_speed) { | |
const arrival_time_s = ((light.dist/ km_speed) * 3.6) + 0.001; | |
const passage_iteration = Math.floor(arrival_time_s / (light.dur)); | |
return passage_iteration %2 === 0; | |
} | |
function computeResponse(proposal = speed, i = 0) { | |
if(i >= lights_data.length) { | |
return proposal; | |
} | |
if(passesAtGreen(lights_data[i], proposal)) { | |
return computeResponse(proposal, i+1); | |
} | |
return computeResponse(proposal - 1, 0); | |
} | |
console.log(computeResponse()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const speed = parseInt(readline());
const lightCount = parseInt(readline());
let allSpeed = [...Array(200).keys()].map(i => i + 1)
let previousDistance = 0
for (let i = 0; i < lightCount; i++) {
var inputs = readline().split(' ');
const distance = parseInt(inputs[0]);
const duration = parseInt(inputs[1]);
allSpeed = allSpeed.filter(v => {
let sign = Math.sin(Math.PI * (distance / (v * 1000 / 3600)) / duration)
let isPassing = sign > 0 ? sign >= 0.0001 : sign >= -0.0001
return isPassing && v <= speed
});
previousDistance = distance
}
// Write an answer using console.log()
// To debug: console.error('Debug messages...');
console.log(Math.max(...allSpeed));