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 11<br />

Marcamos el mínimo como procesado. Continuando el proceso cuando se han marcado todos<br />

como procesados, llegamos al resultado:<br />

0 1 2 3 4 5 6<br />

true true true true true true true<br />

0 1 1 2 3 3 4<br />

El valor mínimo para llegar al nodo 6 es 4.<br />

Este algoritmo se ha utilizado en la solución para hallar el resultado. Primero se halla el mínimo,<br />

luego se hace lo mismo con la matriz transpuesta, y finalmente con ambas soluciones, se crea<br />

una matriz que nos permitirá hallar <strong>los</strong> valores próximos al mínimo, que es el resultado pedido.<br />

Programa Java que soluciona el problema<br />

/*<br />

* Problema: Almost<br />

* Solution by Alessandro <strong>de</strong> Luna Almeida<br />

*<br />

* Dijkstra<br />

*<br />

*/<br />

import java.io.BufferedRea<strong>de</strong>r;<br />

import java.io.IOException;<br />

import java.io.InputStreamRea<strong>de</strong>r;<br />

import java.io.PrintStream;<br />

import java.io.StreamTokenizer;<br />

import java.util.Arrays;<br />

public class sol {<br />

static int m, n, s, d, grafo[][], grafo2[][];<br />

static StreamTokenizer in;<br />

static PrintStream out;<br />

static int[] dist, dist2;<br />

static boolean readdata() throws IOException{<br />

in.nextToken();<br />

n = (int)in.nval;<br />

if(n==0)<br />

return false;<br />

in.nextToken();<br />

m = (int)in.nval;<br />

in.nextToken();<br />

s = (int)in.nval;<br />

in.nextToken();<br />

d = (int)in.nval;

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

Saved successfully!

Ooh no, something went wrong!