14.01.2013 Views

Soluciones y Explicación de los problemas ACM ... - ICPC Bolivia

Soluciones y Explicación de los problemas ACM ... - ICPC Bolivia

Soluciones y Explicación de los problemas ACM ... - ICPC Bolivia

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Explicaciones a <strong>los</strong> <strong>problemas</strong> South American Regionals 2008 6<br />

Análisis <strong>de</strong>l Problema B<br />

Este problema es muy sencillo, fue propuesto el 2007 y se usó <strong>de</strong> problema <strong>de</strong> entrenamiento<br />

para el 2008. Analizando <strong>los</strong> datos <strong>de</strong> entrada nos damos cuenta que existen un máximo <strong>de</strong> 11<br />

atacantes y 11 <strong>de</strong>fensores.<br />

Or<strong>de</strong>nando <strong>los</strong> datos <strong>de</strong> acuerdo a la distancia, po<strong>de</strong>mos comparar la distancia <strong>de</strong>l primer<br />

atacante con la distancia <strong>de</strong>l segundo <strong>de</strong>fensor. Esto correspon<strong>de</strong> a las posiciones 0 y 1. más<br />

<strong>de</strong>talle pue<strong>de</strong> ver en el código adjunto.<br />

Programa Java que soluciona el problema<br />

import java.io.*;<br />

import java.util.*;<br />

class main {<br />

static int[] ataque = new int[11], <strong>de</strong>fensa = new int[11];<br />

public static final void main(String[] args) throws Exception {<br />

Scanner s = new Scanner(new InputStreamRea<strong>de</strong>r(System.in));<br />

while (true) {<br />

int A = s.nextInt();<br />

int D = s.nextInt();<br />

if (A == 0 && D == 0)<br />

break;<br />

for (int i = 0; i < A; i++) {<br />

ataque[i] = s.nextInt();<br />

}<br />

for (int j = 0; j < D; j++) {<br />

<strong>de</strong>fensa[j] = s.nextInt();<br />

}<br />

Arrays.sort(ataque);<br />

Arrays.sort(<strong>de</strong>fensa);<br />

if (ataque[0] < <strong>de</strong>fensa[1]) {<br />

System.out.println("Y");<br />

} else {<br />

System.out.println("N");<br />

}<br />

}<br />

}<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!