Defibrillators puzzle discussion

They are given in degrees, not in radians.

Awesome.
Lat/long are given in radians, not in degree as said MrAnderson

Thx!

I found my mistake 
 it took me a while and so obvious !!!
I hate myself in these case :stuck_out_tongue:

Bless u sir.

[solved]
Hi,
I have got a mistake for test number 3

I found nearest “Caisse d’assurance retraite et de la Sante au travail” (distance=0.0218670137907) than “Caisse Primaire d’Assurance Maladie” (distance=0.0329447601689)
the test #1 2 and 4 are ok but this doesn’t work

I’m with python
Have you got an idea for my problem ?
Thanks a lot
I found the problem in my formula for distance.

Hello tous le monde !

J’ai bien aimĂ© ce puzzle mais je vous conseil de ne pas prendre la formule donnĂ© dans l’énoncĂ© pour le calcul de distance car perso c’est ce qui faisait buger la pg

Mais plutĂŽt celle ci :wink:

d = R.acos(sin(a).sin(b)+cos(a).cos(b).cos(c-d))

Elle fait peur certe fonctionne trĂšs bien et le must c’est que cela se fait en une Ă©tape et pas trois !

a = Lat A
b = Lat B
c = Long A
d = Long B ----- Bien sur toutes ces donnĂ©es sont quand mĂȘme a rentrĂ© en radians :wink:

I had the same problem. don’t use the provided triangulation formula. Simplify it :

Sqrt((LON1 - LON2)^2 + (LAT1 - LAT2)^2)

That fixed may problems. I was using doubles in C#.

JavaScript.

I have an issue where I pass all test cases in the IDE, but then when I submit I fail on “Complete file”. I can’t figure it out why. Is anyone here able to help?

const radCon = (180 / Math.PI)
const LON = readline().replace(',','.') * radCon;
const LAT = readline().replace(',','.') * radCon;
const N = +(readline());
let shortestDistance = Infinity;
let nameOfShortest = '';
for (let i = 0; i < N; i++) {
    let [,name,,, long, lat] = readline().split(';');
    long = long.replace(',', '.') * radCon;
    lat = lat.replace(',', '.') * radCon;
    x = (long - LON) * Math.cos((LAT + lat) / 2);
    y = lat - LAT;
    distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
    if (distance <= shortestDistance){
        shortestDistance = distance;
        nameOfShortest = name;
    }
}
print(nameOfShortest);

DO NOT forget to add “.0” at the end of numbers when computing with floats or doubles !

The debugger in the browser doesent seem to want to replace commas with dots. So i cant parse the strings to doubles and my whole algorithm doesent work. Feelsgood when you cant even test your code.

In Java, replace returns a new String, it doesn’t modify the current String.

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(char,%20char)

actually, you can check the first pitfall of this playground: https://tech.io/playgrounds/1097/the-most-common-java-pitfalls

Input values - that includes lat lng of User (first and second line of input) and not only - as I assumed - data for defribillators. Many minutes were lost :slight_smile:

Thanks for the hint :slight_smile:

Mate, you saved me so many hours here! Ty a lot!

I dont get it inside the IDE all test work with sucess. when i submit the
“single possibility” test appear as Red. Why??? 0.o

2 Likes

Strange


In VS my code works correct, but in website - wrong.

Website cannot round a double value with many digits after ’ , '

I’ve tried Math.Round, but it doesn’t work

Bonjour,

j’ai fini l’exercice mais lorsque je soumets mes rĂ©sultats, l’exercice n°3 n’est pas acceptĂ©.

J’ai changĂ© mon code plusieurs fois mais rien ne change, pouvez-vous me conseiller?

Well, the same old song - program passed all testcases in IDE, but failed on “Complete file 2” on Submit. I’ve tried all recomended - using different formulas, removing converting from degrees to rads, changing double to long double but nothing helped. And CG doesn’t give any clue what goes wrong. Thanks for killing my motivation

Understand. It was timeout problem. After some optimization of my code (C++) it passed. But I still think, that CG should tell the type of error - e. g. “timeout error” or “wrong answer” or something like this

I’m surprised that test set allow passing with wrong formulae. I’ve misspelled some part of it and was ok, other people simplify formula, some of them even overlook to convert to radians
 Maybe add some test cases with points far away, to make errors be visible?