TOPIC

PROBLEM 1404 - URI Fórum 1.0

beecrowd asked on May 21 2013

URI Online Judge Fórum 1.0

MOD

This topic was solved and cannot recieve new replies.

  • wsantos0 replied 8 years ago

    No aguardo respostas, dicas de como pensar para resolver, etc.....

  • wsantos0 replied 8 years ago

    Boa tarde! Estou com um problema no meu código, pois não está passando no último caso de teste. Porém não encontrei o problema ainda. Se alguém puder me ajudar a passar, fico muito grato! Segue o código:

    #include <stdio.h>
    #include <stdlib.h>
    #include <cstring>
    
    int acharCapturas(int i, int j, int tab[20][20]) {
        int nCapturas = 0, maxCapturas;
    
        if(tab[i-1][j-1] == 2 && !tab[i-2][j-2] && i-2 >= 0 && j-2 >= 0) {
            nCapturas++;
            tab[i-1][j-1] = 0;
            nCapturas += acharCapturas(i-2, j-2, tab);
        }
    
        maxCapturas = nCapturas;
    
        if(tab[i-1][j+1] == 2 && !tab[i-2][j+2] && i-2 >= 0) {
            nCapturas = 1;
            tab[i-1][j+1] = 0;
            nCapturas += acharCapturas(i-2, j+2, tab);
        }
    
        if(nCapturas > maxCapturas)
            maxCapturas = nCapturas;
    
        if(tab[i+1][j-1] == 2 && !tab[i+2][j-2] && j-2 >= 0) {
            nCapturas = 1;
            tab[i+1][j-1] = 0;
            nCapturas += acharCapturas(i+2, j-2, tab);
        }
    
        if(nCapturas > maxCapturas)
            maxCapturas = nCapturas;
    
        if(tab[i+1][j+1] == 2 && !tab[i+2][j+2]) {
            nCapturas = 1;
            tab[i+1][j+1] = 0;
            nCapturas += acharCapturas(i+2, j+2, tab);
        }
    
        if(nCapturas > maxCapturas)
            maxCapturas = nCapturas;
    
        return maxCapturas;
    }
    
    int main() {
        int linhas, colunas, i, j, tab[20][20];
        scanf("%d %d", &linhas, &colunas);
        while(linhas && colunas) {
            int maxCapturas = 0, nCapturas;
            memset(tab, 1, sizeof(tab));
    
            for(i = 0 ; i < linhas ; i++) {
                for(j = (i % 2  == 0 ? 0 : 1) ; j < colunas ; j+=2) {
                    scanf("%d", &tab[i][j]);
                }
            }
    
            for(i = 0 ; i < linhas ; i++) {
                for(j = (i % 2 == 0 ? 0 : 1) ; j < colunas ; j+=2) {
                    if(tab[i][j] == 1) {
                        nCapturas = acharCapturas(i, j, tab);
                        if(nCapturas > maxCapturas)
                            maxCapturas = nCapturas;
                    }
                }
            }
    
            printf("%d\n", maxCapturas);
            scanf("%d %d", &linhas, &colunas);
        }
    
        return 0;
    }
  • Quandray replied 8 years ago

    A descrição do problema diz "Cada descrição consiste em [(N x M)/2 ] inteiros", mas o primeiro exemplo tem n = 3 & m = 3, então 2 1 2 0 1. Eu acho que a descrição do problema deve dizer "Cada descrição consiste de ceil((N x M )/2) inteiros"

    The problem description says "Each description consists of [(N x M)/2] integers" but the first sample has n=3 & m=3 then 2 1 2 0 1. I think the problem description should say "Each description consists of ceil((N x M)/2) integers"