Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: alulab11
- *
- * Created on 20 de junio de 2014, 11:31 AM
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 4
- void buscaPo(int fil, int col,int tam,int* sx, int *sy){
- *sx = fil+1;
- *sy = col;
- if (*sx == tam){
- *sx = 0;
- *sy = col+1;
- }
- }
- int esValido(char A[MAX][MAX],int tam, int fil, int col){
- int i;
- if (A[fil][col]== 'X'|| A[fil][col]=='T')
- return 0;
- for(i=col-1;i>=0;i--){
- if (A[fil][i] == 'X') break;
- if (A[fil][i] == 'T') return 0;
- }
- for(i=fil-1;i>=0;i--){
- if (A[i][col] == 'X') break;
- if (A[i][col] == 'T') return 0;
- }
- return 1;
- }
- void dontGetRooked(int fil, int col, char A[MAX][MAX],int tam,
- int *cantTorres, int *maxTorres){
- int nuevoX,nuevoY;
- if (col == tam){
- if(*cantTorres > *maxTorres)
- *maxTorres = *cantTorres;
- return;
- }
- buscaPo(fil,col,tam,&nuevoX,&nuevoY);
- if (esValido(A,tam,fil,col)){
- A[fil][col] = 'T';
- (*cantTorres)++;
- dontGetRooked(nuevoX,nuevoY,A,tam,cantTorres,maxTorres);
- A[fil][col]= '.';
- (*cantTorres)--;
- }
- dontGetRooked(nuevoX,nuevoY,A,tam,cantTorres,maxTorres);
- return;
- }
- int main(int argc, char** argv) {
- char c;
- int tam;
- char A[MAX][MAX];
- int maxTorres,contTorres;
- scanf("%d",&tam);
- while(tam>0){
- maxTorres = 0;
- contTorres = 0;
- int i,j;
- for (i=0;i<tam;i++){
- for(j=0;j<tam;j++){
- scanf(" %c",&A[i][j]);
- }
- }
- dontGetRooked(0,0,A,tam,&contTorres,&maxTorres);
- printf("%d\n",maxTorres);
- scanf("%d",&tam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement