I just had a hell of a time with this problem and my issue ended up being simple: I had been using parseFloat() when reading in the readline() for LON and LAT. Since the coordinates have commas, it would truncate the input to 3 and 43. This caused me such a headache, since I kept on double checking my math over and over… ugh. So yeah, don’t do what I did. Also, had a few issues with running an input through parseFloat() and Number(), but they ended up still being strings, so when I went to use + to sum, it actually concatenated. So if using javaScript look out for that…
Lo mismo me pasa a mí solo que con el 1 por más que traté de simplificar el código o meter más validaciones me sigue dando 75%
[In English, please (google traduction below):
The same thing happens to me, only with 1, no matter how much I tried to simplify the code or put more validations, it still gives me 75%]
The proposed correct algorithm to this Defribillators Puzzle is NOT correct.
It is accepting Maison de la Prevention as the location of the nearest defribillator whereas Hotel de Ville distance (4867207623.741239566) is shorter than that of Maison de la Prevention (4867208230.410655004).
I have the same result for the Complete file test.
*$g++ -o main .cpp $main
Caisse Primaire d’Assurance Maladie<-- distance is–>5.10351
CRR<-- distance is -->0.40642
I wrote a separate code to test these two.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <regex>
using namespace std;
struct Point{
long double longitude, latitude;
};
long double toRadians(const long double degree)
{
// cmath library in C++
// defines the constant
// M_PI as the value of
// pi accurate to 1e-30
long double one_deg = (M_PI) / 180;
return (one_deg * degree);
}
Point GetPoint(long double lon, long double lat)
{
Point point;
point.longitude = toRadians(lon);
point.latitude = toRadians(lat);
return point;
}
long double GetDistance(Point A, Point B)
{
long double distance = 0.0;
long double x = 0.0;
long double y = 0.0;
x = (B.longitude - A.longitude) * cos((A.latitude + B.latitude)/2);
y = B.latitude -A.latitude;
return distance = std::sqrt( pow(x, 2) +pow(y, 2)) *6371;
}
int main()
{
Point playerpos = GetPoint(3.874054, 43.606779);
Point defifPos = GetPoint(3.82126953167633, 43.6322018829039);
long double d = GetDistance(playerpos, defifPos);
cout<<"Caisse Primaire d'Assurance Maladie" << "<-- distance is-->" << d<<endl;
Point defifPos1 = GetPoint(3.87409666178277,43.610433894746);
long double d1 = GetDistance(playerpos, defifPos1);
cout<<"CRR" << "<-- distance is -->" << d1<<endl;
return 0;
}
Hello, I am using C# and stuck on this trying to store the DFIB inputs as variable so that they can be split / manipulated to isolate the LON / LAT value of each input sequence. I am new to this so it is likely that I am going about this the wrong way but I’m not sure. Any suggestions would be appreciated!
The issue I’m having with the below code is that this stores each input as an index in the list. However, now if I try something like defibsAllData[i].Split(";"); for example, I get an error for trying to convert string [] to string.
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Solution
{
static void Main(string[] args)
{
double LON = Double.Parse(Console.ReadLine().Replace(",","."));
double LAT = Double.Parse(Console.ReadLine().Replace(",","."));
int N = int.Parse(Console.ReadLine());
var defibsAllData = new List();
for (int i = 0; i < N; i++)
{
defibsAllData.Add(Console.ReadLine().Replace(",","."));
}
What you’re showing should work, from what I gather you probably wrote something like string s = defibsAllData[i].split(";")
which would not be allowed since Split returns an array of strings (aka string[] here).
Hi, I’m actually working on Defibrillators puzzle
I’ve having issues to get the good distance, I rand my code again and again and compare it to the formulas but I’m not able to see what’s wrong with what I’ve done…
Maybe someone will see ? (I whould be so gratefull :))
My code in c# below :
After my C code passed all tests in the IDE, I submitted my code and the validator says I failed to pass the first test because it suspects that I have “hard coded” the answer but I didn’t. The validator is invalid.
It’s a generic message to say that your code failed, that doesn’t mean you hardcoded anything.
As for the validity, who’s more likely to be wrong, the 60k people that passed it or you ?