Results 1 to 6 of 6
  1. #1
    spinter is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Runtime error , ACM-ICPC 3807 MARBLE GAME PROBLEM

    i have the error of the title i have that code if someone can help me thxxxxxx
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package marble3;
    
    /**
     *
     *
     */
    import java.util.*;
    
     class Main {
    
        /**
         * @param args the command line arguments
         */
         
    
         static void main(String[] args) {
            // TODO code application logic here
    
    
    
            int tam = 0;
            int nMarble = 0;
            int[][] tablero = new int[tam][tam];
            ArrayList<Wall> muros = new ArrayList<Wall>();
            int nWall = 0;
            int Caso = 1;
            Scanner scan = new Scanner(System.in);
            String linea = scan.nextLine();
    
    
            char caracterTam = linea.charAt(0);
            String cadenaTam = "" + caracterTam;
            tam = Integer.parseInt(cadenaTam);
            char caracterMarble = linea.charAt(2);
            String cadenaMarble = "" + caracterMarble;
            nMarble = Integer.parseInt(cadenaMarble);
            char caracterWall = linea.charAt(4);
            String cadenaWall = "" + caracterWall;
            nWall = Integer.parseInt(cadenaWall);
    
    
    
    
            while (tam != 0 && nMarble != 0 && nWall != 0) {
    
                tablero = new int[tam][tam];
                for (int i = 0; i < tam; i++) {
                    for (int k = 0; k < tam; k++) {
                        tablero[i][k] = 0;
                    }
                }
    
    
                for (int i = 1; i < nMarble + 1; i++) {
    
                    linea = scan.nextLine();
                    int x, y;
    
                    char caracterX = linea.charAt(0);
                    String cadenaX = "" + caracterX;
                    x = Integer.parseInt(cadenaX);
                    char caracterY = linea.charAt(2);
                    String cadenaY = "" + caracterY;
                    y = Integer.parseInt(cadenaY);
                    tablero[x][y] = i;
    
    
                }
    
    
    
                for (int i = 1; i < nMarble + 1; i++) {
                    int x, y;
                    linea = scan.nextLine();
                    char caracterX = linea.charAt(0);
                    String cadenaX = "" + caracterX;
                    x = Integer.parseInt(cadenaX);
                    char caracterY = linea.charAt(2);
                    String cadenaY = "" + caracterY;
                    y = Integer.parseInt(cadenaY);
                    tablero[x][y] = -i;
                }
    
    
    
    
    
                for (int i = 0; i < nWall; i++) {
                    linea = scan.nextLine();
                    Wall w = new Wall();
                    char caracterMuro = linea.charAt(0);
                    String cadenaMuro = "" + caracterMuro;
                    w.filaa = Integer.parseInt(cadenaMuro);
                    caracterMuro = linea.charAt(2);
                    cadenaMuro = "" + caracterMuro;
                    w.columnaa = Integer.parseInt(cadenaMuro);
                    caracterMuro = linea.charAt(4);
                    cadenaMuro = "" + caracterMuro;
                    w.filab = Integer.parseInt(cadenaMuro);
                    caracterMuro = linea.charAt(6);
                    cadenaMuro = "" + caracterMuro;
                    w.columnab = Integer.parseInt(cadenaMuro);
                    muros.add(w);
    
                }
    
                int movimientos = 0;
                int elemento = 0;
                ArrayList<tablerosVisitados> tableros = new ArrayList<tablerosVisitados>();
                tablerosVisitados tableroInicial = new tablerosVisitados(tablero, tam, 0);
                tableros.add(tableroInicial);
                boolean movimientoValido;
                boolean resuelto = false;
                boolean sinSolucion = false;
                while (resuelto == false && sinSolucion == false) {
                    for (int i = 0; i < 4; i++) {
                        tablerosVisitados nuevoTablero = new tablerosVisitados(tableros.get(elemento).tablero, tam, tableros.get(elemento).nummovs);
                        //nuevoTablero = tableros.get(elemento);
                        switch (i) {
                            case 0:
                                movimientoValido = moverArriba(muros, nuevoTablero.tablero, tam);
                                break;
                            case 1:
                                movimientoValido = moverAbajo(muros, nuevoTablero.tablero, tam);
                                break;
                            case 2:
                                movimientoValido = moverDerecha(muros, nuevoTablero.tablero, tam);
                                break;
                            case 3:
                                movimientoValido = moverIzquierda(muros, nuevoTablero.tablero, tam);
                                break;
                            default:
                                movimientoValido = false;
                                break;
                        }
                        if (movimientoValido == true) {
                            if (tablerodistinto(tam, nuevoTablero.tablero, tableros)) {
                                nuevoTablero.nummovs = nuevoTablero.nummovs + 1;
                                tableros.add(nuevoTablero);
                                //   System.out.println("Añade\n");
                                if (tableroResuelto(nuevoTablero.tablero, tam)) {
                                    resuelto = true;
                                    movimientos = nuevoTablero.nummovs;
                                }
                            }
                        }
    
                    }
                    elemento++;
                    if (elemento == tableros.size()) {
                        sinSolucion = true;
                    }
                }
    
                if (resuelto) {
                    System.out.println("Case " + Caso + ": " + movimientos + " moves\n");
                } else {
                    System.out.println("Case " + Caso + ": impossible\n");
                }
                Caso++;
    
    
                linea = scan.nextLine();
                caracterTam = linea.charAt(0);
                cadenaTam = "" + caracterTam;
                tam = Integer.parseInt(cadenaTam);
                caracterMarble = linea.charAt(2);
                cadenaMarble = "" + caracterMarble;
                nMarble = Integer.parseInt(cadenaMarble);
                caracterWall = linea.charAt(4);
                cadenaWall = "" + caracterWall;
                nWall = Integer.parseInt(cadenaWall);
    
    
    
            }
    
        }
    
        static boolean tablerodistinto(int tam, int[][] tablero, ArrayList<tablerosVisitados> tableros) {
            boolean esIgual;
            int[][] t = new int[tam][tam];
            for (int i = 0; i < tableros.size(); i++) {
                t = tableros.get(i).tablero;
                esIgual = true;
                for (int j = 0; j < tam; j++) {
                    for (int k = 0; k < tam; k++) {
                        if (t[j][k] != tablero[j][k]) {
                            esIgual = false;
                        }
                    }
                }
                if (esIgual == true) {
                    return false;
                }
    
            }
            return true;
        }
    
        static boolean muroArriba(ArrayList<Wall> muros, int fila, int columna) {
    
            boolean i = false;
            for (Wall existe : muros) {
                if ((existe.filaa == fila && existe.columnaa == columna && existe.filab == fila + 1 && existe.columnab == columna)
                        || (existe.filaa == fila + 1 && existe.columnaa == columna && existe.filab == fila && existe.columnab == columna)) {
                    i = true;
                    break;
                }
            }
            return i;
    
        }
    
        static boolean muroAbajo(ArrayList<Wall> muros, int fila, int columna) {
    
            boolean i = false;
            for (Wall existe : muros) {
                if ((existe.filaa == fila && existe.columnaa == columna && existe.filab == fila - 1 && existe.columnab == columna)
                        || (existe.filaa == fila - 1 && existe.columnaa == columna && existe.filab == fila && existe.columnab == columna)) {
                    i = true;
                    break;
                }
            }
            return i;
    
        }
    
        static boolean muroDerecha(ArrayList<Wall> muros, int fila, int columna) {
    
            boolean i = false;
            for (Wall existe : muros) {
                if ((existe.filaa == fila && existe.columnaa == columna + 1 && existe.filab == fila && existe.columnab == columna)
                        || (existe.filaa == fila && existe.columnaa == columna && existe.filab == fila && existe.columnab == columna + 1)) {
                    i = true;
                    break;
                }
            }
            return i;
    
        }
    
        static boolean muroIzquierda(ArrayList<Wall> muros, int fila, int columna) {
            if (columna == 0) {
                return true;
            } else {
                boolean i = false;
                for (Wall existe : muros) {
                    if ((existe.filaa == fila && existe.columnaa == columna - 1 && existe.filab == fila && existe.columnab == columna)
                            || (existe.filaa == fila && existe.columnaa == columna && existe.filab == fila && existe.columnab == columna - 1)) {
                        i = true;
                        break;
                    }
                }
                return i;
            }
        }
    
        static boolean bolaArriba(int[][] tablero, int fila, int columna) {
            if (tablero[fila - 1][columna] > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean bolaAbajo(int[][] tablero, int fila, int columna) {
            if (tablero[fila + 1][columna] > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean bolaDerecha(int[][] tablero, int fila, int columna) {
            if (tablero[fila][columna + 1] > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean bolaIzquierda(int[][] tablero, int fila, int columna) {
            if (tablero[fila][columna - 1] > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean algoArriba(ArrayList<Wall> muros, int[][] tablero, int tam, int fila, int columna) {
            if (fila == 0) {
                return true;
            } else if (bolaArriba(tablero, fila, columna)) {
                return true;
            } else if (muroArriba(muros, fila, columna)) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean algoAbajo(ArrayList<Wall> muros, int[][] tablero, int tam, int fila, int columna) {
            if (fila == tam - 1) {
                return true;
            } else if (bolaAbajo(tablero, fila, columna)) {
                return true;
            } else if (muroAbajo(muros, fila, columna)) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean algoDerecha(ArrayList<Wall> muros, int[][] tablero, int tam, int fila, int columna) {
            if (columna == tam - 1) {
                return true;
            } else if (bolaDerecha(tablero, fila, columna)) {
                return true;
            } else if (muroDerecha(muros, fila, columna)) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean algoIzquierda(ArrayList<Wall> muros, int[][] tablero, int tam, int fila, int columna) {
            if (columna == 0) {
                return true;
            } else if (bolaIzquierda(tablero, fila, columna)) {
                return true;
            } else if (muroIzquierda(muros, fila, columna)) {
                return true;
            } else {
                return false;
            }
        }
    
        static boolean moverArriba(ArrayList<Wall> muros, int[][] tablero, int tam) {
            if (malosHoyosAbajo(muros, tablero, tam) == false) {
                for (int cont = 0; cont < tam; cont++) {
                    // for (int i = tam - 1; i > 0; i++) {
                    for (int i = 0; i < tam; i++) {
                        for (int j = 0; j < tam; j++) {
                            if (tablero[i][j] > 0) {
                                if (algoArriba(muros, tablero, tam, i, j) == false) {
                                    if (tablero[i - 1][j] == tablero[i][j] * (-1)) {
                                        tablero[i - 1][j] = 0;
                                    } else {
                                        tablero[i - 1][j] = tablero[i][j];
                                    }
                                    tablero[i][j] = 0;
                                }
                            }
                        }
                    }
                }
            } else {
                return false;
            }
            return true;
        }
    
        static boolean moverAbajo(ArrayList<Wall> muros, int[][] tablero, int tam) {
            if (malosHoyosAbajo(muros, tablero, tam) == false) {
                for (int cont = 0; cont < tam; cont++) {
                    for (int i = tam - 1; i >= 0; i--) {
                        for (int j = 0; j < tam; j++) {
                            if (tablero[i][j] > 0) {
                                if (algoAbajo(muros, tablero, tam, i, j) == false) {
                                    if (tablero[i + 1][j] == tablero[i][j] * (-1)) {
                                        tablero[i + 1][j] = 0;
                                    } else {
                                        tablero[i + 1][j] = tablero[i][j];
                                    }
                                    tablero[i][j] = 0;
                                }
                            }
                        }
                    }
                }
            } else {
                return false;
            }
            return true;
        }
    
        static boolean moverDerecha(ArrayList<Wall> muros, int[][] tablero, int tam) {
            if (malosHoyosDerecha(muros, tablero, tam) == false) {
                for (int cont = 0; cont < tam; cont++) {
                    for (int i = 0; i < tam; i++) {
                        // for (int j = 0; j < tam; j++) {
                        for (int j = tam - 1; j >= 0; j--) {
                            if (tablero[i][j] > 0) {
                                if (algoDerecha(muros, tablero, tam, i, j) == false) {
                                    if (tablero[i][j + 1] == tablero[i][j] * (-1)) {
                                        tablero[i][j + 1] = 0;
                                    } else {
                                        tablero[i][j + 1] = tablero[i][j];
                                    }
                                    tablero[i][j] = 0;
                                }
                            }
                        }
                    }
                }
            } else {
                return false;
            }
            return true;
    
        }
    
        static boolean moverIzquierda(ArrayList<Wall> muros, int[][] tablero, int tam) {
            if (malosHoyosIzquierda(muros, tablero, tam) == false) {
                for (int cont = 0; cont < tam; cont++) {
                    for (int i = 0; i < tam; i++) {
                        for (int j = 0; j < tam; j++) {
                            // for (int j = tam - 1; j >= 0; j--) {
                            if (tablero[i][j] > 0) {
                                if (algoIzquierda(muros, tablero, tam, i, j) == false && tablero[i][j] > 0) {
                                    if (tablero[i][j - 1] == tablero[i][j] * (-1)) {
                                        tablero[i][j - 1] = 0;
                                    } else {
                                        tablero[i][j - 1] = tablero[i][j];
                                    }
                                    tablero[i][j] = 0;
                                }
                            }
                        }
                    }
                }
            } else {
                return false;
            }
            return true;
        }
    
        static boolean malHoyoArriba(int[][] tablero, int fila, int columna) {
            for (int i = fila - 1; i >= 0; i++) {
                if (tablero[i][columna] < 0) {
                    if (tablero[i][columna] == tablero[fila][columna] * (-1)) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }
            return false;
        }
    
        static boolean malHoyoAbajo(int[][] tablero, int tam, int fila, int columna) {
            for (int i = fila + 1; i < tam; i++) {
                if (tablero[i][columna] < 0) {
                    if (tablero[i][columna] == tablero[fila][columna] * (-1)) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }
            return false;
        }
    
        static boolean malHoyoDerecha(int[][] tablero, int tam, int fila, int columna) {
            for (int i = columna + 1; i < tam; i++) {
                if (tablero[fila][i] < 0) {
                    if (tablero[fila][i] == tablero[fila][columna] * (-1)) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }
            return false;
        }
    
        static boolean malHoyoIzquierda(int[][] tablero, int fila, int columna) {
            for (int i = columna - 1; i >= 0; i++) {
                if (tablero[fila][i] < 0) {
                    if (tablero[fila][i] == tablero[fila][columna] * (-1)) {
                        return false;
                    } else {
                        return true;
                    }
                }
            }
            return false;
        }
    
        static boolean malosHoyosDerecha(ArrayList<Wall> muros, int[][] tablero, int tam) {
            int col;
            for (int i = 0; i < tam; i++) {
                col = -1;
                for (int j = 0; j < tam; j++) {
    
                    if (tablero[i][j] > 0) {
                        col = j;
                    }
                    if (col != -1) {
                        if (tablero[i][j] < 0 && muroIzquierda(muros, i, j) == false && tablero[i][j] != tablero[i][col] * (-1)) {
                            return true;
                        }
                    }
    
                }
            }
            return false;
        }
    
        static boolean malosHoyosIzquierda(ArrayList<Wall> muros, int[][] tablero, int tam) {
            int col;
            for (int i = 0; i < tam; i++) {
                col = -1;
                for (int j = tam - 1; j >= 0; j--) {
    
                    if (tablero[i][j] > 0) {
                        col = j;
                    }
                    if (col != -1) {
                        if (tablero[i][j] < 0 && muroDerecha(muros, i, j) == false && tablero[i][j] != tablero[i][col] * (-1)) {
                            return true;
                        }
                    }
    
                }
            }
            return false;
        }
    
        static boolean malosHoyosArriba(ArrayList<Wall> muros, int[][] tablero, int tam) {
            int col;
            for (int i = tam - 1; i >= 0; i++) {
                col = -1;
                for (int j = 0; j < tam; j++) {
    
                    if (tablero[j][i] > 0) {
                        col = i;
                    }
                    if (col != -1) {
                        if (tablero[j][i] < 0 && muroIzquierda(muros, j, i) == false && tablero[j][i] != tablero[j][col] * (-1)) {
                            return true;
                        }
                    }
    
                }
            }
            return false;
        }
    
        static boolean malosHoyosAbajo(ArrayList<Wall> muros, int[][] tablero, int tam) {
            int col;
            for (int i = 0; i > tam; i++) {
                col = -1;
                for (int j = 0; j < tam; j++) {
    
                    if (tablero[j][i] > 0) {
                        col = i;
                    }
                    if (col != -1) {
                        if (tablero[j][i] < 0 && muroIzquierda(muros, j, i) == false && tablero[j][i] != tablero[j][col] * (-1)) {
                            return true;
                        }
                    }
    
                }
            }
            return false;
        }
    
        static boolean tableroResuelto(int[][] tablero, int tam) {
            for (int i = 0; i < tam; i++) {
                for (int j = 0; j < tam; j++) {
                    if (tablero[i][j] != 0) {
                        return false;
                    }
                }
            }
    
            return true;
        }
    
    
        static class Wall {
    
            int filaa;
            int columnaa;
            int filab;
            int columnab;
    
            Wall() {
                filaa = columnaa = filab = columnab = 0;
            }
        }
    
         static class tablerosVisitados {
    
            int[][] tablero;
            int nummovs;
    
            tablerosVisitados(int[][] t, int tam, int m) {
                tablero = new int[tam][tam];
                for (int i = 0; i < tam; i++) {
                    for (int k = 0; k < tam; k++) {
                        tablero[i][k] = t[i][k];
                    }
                }
                nummovs = m;
            }
        }
    
    
    }
    Last edited by spinter; 01-22-2012 at 03:15 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Runtime error , ACM-ICPC 3807 MARBLE GAME PROBLEM

    i have the error of the title
    Can you post the full text of the error message. I do not recognize what you have in the title.

  3. #3
    spinter is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Runtime error , ACM-ICPC 3807 MARBLE GAME PROBLEM

    yes , sorry. this is the msg

    Your submission for the problem 3807-Marble Game has failed with veredict Runtime error

    this means that the execution of your progra didn't finish properly.
    Remember to always terminate your code with the exit code 0,
    best regards,
    The ACM-IPCP live Archive team

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Runtime error , ACM-ICPC 3807 MARBLE GAME PROBLEM

    Can you explain what you need help with?
    Remember to always terminate your code with the exit code 0,
    How does your code exit?
    Does it use: System.exit(0);

  5. #5
    spinter is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default Re: Runtime error , ACM-ICPC 3807 MARBLE GAME PROBLEM

    i don't know what exit ACM only says you the error or if it is accepted, and about the exit i don't understand what i must do , i think my code it's good but ACM test says no then sure are a error but i can't find it then i post it here , if someone know xD, about System.exit(0), where i must put it???

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: Runtime error , ACM-ICPC 3807 MARBLE GAME PROBLEM

    Where does your program exit? Where is the last statement that executes in the code?
    Put the System.exit(0) there.

Similar Threads

  1. help marble game
    By spinter in forum Advanced Java
    Replies: 1
    Last Post: 01-03-2012, 03:14 PM
  2. ACM-ICPC >> my Dream
    By Dina147 in forum New To Java
    Replies: 8
    Last Post: 12-14-2011, 10:17 PM
  3. Replies: 0
    Last Post: 11-04-2011, 02:36 PM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. Are there anybody who participated in ACM ICPC?
    By javalover in forum Advanced Java
    Replies: 2
    Last Post: 04-19-2008, 01:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •