Why / 200.0 and *1000?
Hi guys,
little issue with this puzzle, when I am using āpiā and ācosā as requested it tells me it doesnāt existā¦despite the āmath importā at the beginningā¦
Thanks in advance
In Python?
How is the import written?
Yeah sorry, itās in Python (not Python 3), and itās written āimport mathāā¦ I tried several time to refresh, didnāt change anything
Are you using math.cos?
No I didnāt tryā¦ should I you math.pi too then ?
Great it worked ! thank you !
I never had to use this way, does it work like this for every package ?
Yes, you can do, either:
import math
print(math.cos(math.pi))
Or:
from math import cos,pi
print(cos(pi))
Okay thank you for the explanation
So for example I could write my code normally and at the end, go back to the top of the code and do āfrom math import cos,piā and it should work right ?
Thank you again guys !
You should write from math import cos,pi immediately even if you can write it everywhere in your code (before the use of cos and pi of course).
Hi! In C++, Like a lot of people here, I have complete all tests but I donāt have 100%.
For me, the problem is in the first test. I donāt know if the name is important but during the game the first test is āExampleā and in the score page it is āSingle possibilityā.
I have used double or float, doesnāt matter. I have put << endl for the answer.
I donāt have other idea.
Thx
Does your code work if the information of only 1 defibrillator is provided in the game input?
To be sure, I tested to put āN = 1ā before the loop to simulate only 1 defibrillator. It works.
Chingmann has helped me and it works. I forgot to convert degree to radian
My C# code, which works fine in VS, isnāt returning the expected results on here.
After finnicking about for longer than Iād like to admit it turned out my numbers were off, though I beleive that I converted them correctly.
Am I being an Idiot?
Do you see that your second Console.WriteLine is the same as the first one? That means you have to fix the line between them.
Hint: string.Replace() does not act the way you think it doesā¦
I already figured it out thanks to Chingmann. It was even more glaringly obvious in hindsight than usual and Iām stricken with shame. But such boorishly blatant blunders bare benefits, I will not make this mistake again.
I also had the problem, that the formula provided by the webpage listed in external resources is too precise!
Simple trig will do the deal and get you 100%
Here is the javascript:
function calculateDistance(user, defibrillator){
let distance = Math.sqrt(Math.pow(defibrillator.latitude - user.latitude, 2) + Math.pow(defibrillator.longitude - user.longitude, 2));
return distance;
}
Hi,
I have a problem with my code.
My code is working only in 50% of cases.
Somebody can understand the reason?
JAVA
import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
double lou = Double.parseDouble(in.next().replaceAll("," , "."));
//System.out.println(lou);
double lau = Double.parseDouble(in.next().replaceAll("," , "."));
int n = in.nextInt();
if (in.hasNextLine()) {
in.nextLine();
}
int[] id = new int[n];
String[] nam = new String[n];
String[] add = new String[n];
String[] pho = new String[n];
double[] lon = new double[n];
double[] lat = new double[n];
for (int i = 0; i < n; i++) {
char[] def = in.nextLine().toCharArray();
int dle = def.length;
int con = 0;
String aux = "";
for(int j = 0; j < dle; j++){
if(def[j] != ';'){
aux += def[j];
con--;
}
else if(con == 0){
id[i] = Integer.parseInt(aux);
aux = "";
}
else if(con == 1){
nam[i] = aux;
aux = "";
}
else if(con == 2){
add[i] = aux;
aux = "";
}
else if(con == 3){
pho[i] = aux;
aux = "";
}
else if(con == 4){
aux = aux.replaceAll("," , ".");
//System.out.println(aux);
lon[i] = Double.parseDouble(aux);
}
else if(con == 5){
aux = aux.replaceAll("," , ".");
lat[i] = Double.parseDouble(aux);
}
con++;
//System.out.println(con);
}
}
double[] dis = new double[n];
int mai = 0;
for(int i = 0; i < n; i++){
double x = (lon[i] - lou) * Math.cos((lat[i] + lau) / 2);
double y = lat[i] - lau;
double res = (Math.sqrt(x * x + y * y) * 6371);
//System.out.println(res);
dis[i] = res;
if(dis[i] <= dis[mai]){
mai = i;
//System.out.println(dis[i]);
}
//System.out.println(i);
}
System.out.print(nam[mai]);
}
}
Call me in private.