Hello...
I was trying to solve it with binary search. However... I got
"incorrect"... Where is the error? Why is wrong my solution? Here is my
Code.
#define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;i++)
template<typename T> inline T sqr(T a) { return a*a; }
int N , luciernagas[510][3][2];
double f(double tiempo){
double punto[3];
FOR(i,0,3){
punto[i] = 0.0;
FOR(j,0,N)
punto[i] += luciernagas[j][i][0] + tiempo*luciernagas[j][i][1];
punto[i] /= (double)N;
}
return sqrt(sqr(punto[0]) + sqr(punto[1]) + sqr(punto[2]));
}
int main(){
int casos;
cin >> casos;
FOR(caso,0,casos){
cin >> N;
FOR(i,0,N)
FOR(j,0,2)
FOR(k,0,3)
cin >> luciernagas[i][k][j];
double maximo = 100000000.0;
double minimo = 0.0;
double medio;
while(eps < maximo - minimo){
assert(minimo < maximo && maximo >= minimo + eps);
medio = (maximo + minimo)/2.0;
double a = medio - eps;
double b = medio + eps;
if (f(a) > f(b)) minimo = medio;
else maximo = medio;
}
double respuestaT = round(medio * 100000.0);
double respuesta = respuestaT/100000.0;
cout << "Case #" << (caso+1) << ": ";
printf("%.8lf %.8lf\n" , f(respuesta) , respuesta);
}
return 0;
}
Thanks!
--
Saul Hidalgo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---