ll responder( int i, int j ){
	if( next[i][j] )
		return memo[i][j];
			
	if( j == col ){
		next[i][j] = -1;
		return memo[i][j] = matriz[i][j];
	}
	
	ll frente, nord, sud, menor;
	
	menor = frente = responder( i, j + 1 );
	next[i][j] = i;
	
	int indice = (i == 1)? lin : (i - 1);
	nord = responder( indice, j + 1 );
	if( nord < menor ){
		menor = nord;
		next[i][j] = indice;
	}else if( nord == menor )
		next[i][j] = MENOR( next[i][j], indice );
				
	indice = (i == lin)? 1 : ( i + 1 );
	sud = responder( indice, j + 1 );
	if( sud < menor ){
		menor = sud;
		next[i][j] = indice;
	}else if( sud == menor )
		next[i][j] = MENOR( next[i][j], indice );

	return memo[i][j] = matriz[i][j] + menor;
		
}
Example #2
0
int main()
{
        int numAreas, t = 1, i;
        int x = -10000, y = 10000, u = 10000, v = -10000;
        int _x, _y, _u, _v;
        char c;
        char buff[200];

        /*

           (x, y)       (u, y)
           *---------*
           |         |
                   |         |
                   *---------*
           (x, v)       (u, v)

        */

        for (scanf("%d", &numAreas); numAreas != 0; scanf("%d", &numAreas))
        {
                for (i = 0; i < numAreas; ++i)
                {
                        scanf("%d %d %d %d", &_x, &_y, &_u, &_v);

                        // testa se não tem intersecção
                        if ((_x > u || _u < x) && (_y < v || _v > y))
                        {
                                printf("Teste %d\nnenhum\n\n", t++);
                                for (; i < numAreas; ++i)
                                        gets(buff);
                                goto fim;
                        }

                        x = MAIOR(x, _x);
                        u = MENOR(u, _u);
                        v = MAIOR(v, _v);
                        y = MENOR(y, _y);

                        // testa se o retangulo formado é incoerente
                        if ((x > u) || (y < v))
                        {
                                printf("Teste %d\nnenhum\n\n", t++);
                                for (; i < numAreas; ++i)
                                        while((c = getchar()) != '\n');
                                goto fim;
                        }

                }
                printf("Teste %d\n%d %d %d %d\n\n", t++, x, y, u, v);
                fim:
                x = -10000;
                y = 10000;
                u = 10000;
                v = -10000;
        }
        return 0;
}
Example #3
0
int main(void){

	int n, i, j, maiorAux, *array, maior, menor;
	
	printf("Digite a quantidade de numeros: ");
	scanf("%d", &n);
	array = (int *) malloc(sizeof(int) * n);
	
	printf("Digite %d numero: ", n);
	
	for(i = 0; i < n; i++){
		scanf("%d", &array[i]);
		if(i == 0){
			maior = array[i];
			menor = array[i];
		}else{
			maior = MAIOR(maior, array[i]);
			menor = MENOR(menor, array[i]);
		}
	}
	maiorAux = maior;
	printf("^\n");
	for(i = 0; i < maior; i++){
		printf("|");
		for(j = 0; j < n; j++){
			if(array[j] == maiorAux){
			     printf("*");				
			     array[j]--;
			}else{
				printf(" ");
			}
		}
		puts("");
		maiorAux--;
	}
	desenhaBarraInferior(n);

	return 0;	
}