Created
October 4, 2015 18:58
-
-
Save diegozr1/b374dadb366eff1fb259 to your computer and use it in GitHub Desktop.
ICPC 2015 Regional
This file contains 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
public class buffed { | |
public static float[] calcularCentroMasa(String cadena ){ | |
cadena = cadena.replaceAll(" ", ""); | |
float counterx=0; | |
float countery=0; | |
float numVertex = Character.getNumericValue(cadena.charAt(0)); | |
float[] aux = new float[2]; | |
for(int i =1;i<cadena.length()-2;i++){ | |
float value = Character.getNumericValue(cadena.charAt(i)); | |
if(i%2 != 0){ | |
counterx += value; | |
}else{ | |
countery += value; | |
} | |
} | |
aux[0]=counterx/numVertex; | |
aux[1]=countery/numVertex; | |
return aux; | |
} | |
public static int[][] getBounds(String p1, String p2){ | |
int[][] aux = new int[2][2]; | |
cadena = cadena.replaceAll(" ", ""); | |
float numVertex = Character.getNumericValue(cadena.charAt(0)); | |
float[] aux = new float[2]; | |
float[] x = new float[numVertex]; | |
float[] y = new float[numVertex]; | |
int cx = 0; | |
int cy = 0; | |
for(int i =1;i<cadena.length()-2;i++){ | |
float value = Character.getNumericValue(cadena.charAt(i)); | |
if(i%2 != 0){ | |
x[cx++] = value; | |
}else{ | |
y[cy++] = value; | |
} | |
} | |
//Implementar sortMinMax, te regresa un arreglo en [0] el minimo y [1] el maximo | |
aux[0][0] = sortMinToMax(cx)[0]; | |
aux[0][1] = sortMinToMax(cx)[1]; | |
aux[1][0] = sortMinToMax(cy)[0]; | |
aux[1][1] = sortMinToMax(cy)[1]; | |
return aux; | |
} | |
public static float[] getVelocidad(String cadena){ | |
float[] vel = new float[2]; | |
vel[0] = Character.getNumericValue(cadena.charAt(cadena.length()-2)); | |
vel[1] = Character.getNumericValue(cadena.charAt(cadena.length()-1)); | |
return vel; | |
} | |
public static float time(String p1, String p2){ | |
float[] cm1 = calcularCentroMasa(p1); | |
float[] cm2 = calcularCentroMasa(p2); | |
float[] vel1 = getVelocidad(p1); | |
float[] vel2 = getVelocidad(p2); | |
float prevX1 = cm1[0]; | |
float prevY1 = cm1[1]; | |
float prevX2 = cm2[0]; | |
float prevY2 = cm2[1]; | |
float collisionTime = 0.0f; | |
for(float time = 0;time<100;time = time + .0001f){ | |
if((prevX1 >= prevX2-0.0001f && prevX1 <= prevX2+0.0001f) && | |
(prevY1 >= prevY2-0.0001f && prevY1 <= prevY2+0.0001f)){ | |
collisionTime = time; | |
System.out.println(time); | |
break; | |
} | |
prevX1 = prevX1 + (time * vel1[0]); | |
prevX2 = prevX2 + (time * vel2[0]); | |
prevY1 = prevY1 + (time * vel1[1]); | |
prevY2 = prevY2 + (time * vel2[1]); | |
} | |
return collisionTime; | |
} | |
public static void printArray(float[] ba){ | |
for(int i = 0; i < ba.length; i++){ | |
System.out.print("["+ba[i]+"]"); | |
} | |
} | |
public static void main(String[] args){ | |
String p2 = "4 18 5 22 9 26 5 22 1 -2 1"; | |
String p1 = "6 3 2 2 4 3 6 6 6 7 4 6 2 2 2"; | |
float time = time(p1, p2); | |
System.out.print(time); | |
//printArray(cm); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment