Vous êtes sur la page 1sur 3

# 18./*ieslabir.

## c- problema "labirintului":iesirea dintr-un labirint specificat in

tr-o matrice L,in care se memoreaza valorile zecimale ale codificarilor binare a
le drumului spre iesire,si anume:
fiecare directie care duce spre iesire e codificata cu 1,iar restul cu 0*/
#include <stdio.h>
#include <conio.h>
#define N 10
#define M 15
#define DIM (N-1)*(M-1)
int L[N][M]={16,16,16,16,16,16,16}
{16, 0, 2, 1, 1, 0,16}
{16, 0, 2, 0, 8, 0,16}
{16, 0, 2, 4, 8, 0,16}
{16, 1, 7, 4, 2, 0,16}
{16, 0, 2, 0, 2, 0,16}
{16,16,16,16,16,16,16}
int d[2][DIM];
int i,n=5,m=5,nr_sol=0,nse=0;
void tiparire(int kmint d[2][DIM]){
int h; nr_sol++;#include <stdio.h>
#include <conio.h>
#define N 10
#define M 15
#define DIM (N-1)*(M-1)
int L[N][M]={16,16,16,16,16,16,16}
{16, 0, 2, 1, 1, 0,16}
{16, 0, 2, 0, 8, 0,16}
{16, 0, 2, 4, 8, 0,16}
{16, 1, 7, 4, 2, 0,16}
{16, 0, 2, 0, 2, 0,16}
{16,16,16,16,16,16,16}
int d[2][DIM];
int i,n=5,m=5,nr_sol=0,nse=0;
void tiparire(int kmint d[2][DIM]){
int h; nr_sol++;#include <stdio.h>
#include <conio.h>
#define N 10
#define M 15
#define DIM (N-1)*(M-1)
int L[N][M]={16,16,16,16,16,16,16}
{16, 0, 2, 1, 1, 0,16}
{16, 0, 2, 0, 8, 0,16}
{16, 0, 2, 4, 8, 0,16}
{16, 1, 7, 4, 2, 0,16}
{16, 0, 2, 0, 2, 0,16}
{16,16,16,16,16,16,16}
int d[2][DIM];
int i,n=5,m=5,nr_sol=0,nse=0;
void tiparire(int kmint d[2][DIM]){
int h; nr_sol++;#include <stdio.h>
#include <conio.h>
#define N 10
#define M 15
#define DIM (N-1)*(M-1)
int L[N][M]={16,16,16,16,16,16,16}
{16, 0, 2, 1, 1, 0,16}
{16, 0, 2, 0, 8, 0,16}
{16, 0, 2, 4, 8, 0,16}
{16, 1, 7, 4, 2, 0,16}
{16, 0, 2, 0, 2, 0,16}

{16,16,16,16,16,16,16}
int d[2][DIM];
int i,n=5,m=5,nr_sol=0,nse=0;
void tiparire(int kmint d[2][DIM]){
int h; nr_sol++;#include <stdio.h>
#include <conio.h>
#define N 10
#define M 15
#define DIM (N-1)*(M-1)
int L[N][M]={16,16,16,16,16,16,16}
{16, 0, 2, 1, 1, 0,16}
{16, 0, 2, 0, 8, 0,16}
{16, 0, 2, 4, 8, 0,16}
{16, 1, 7, 4, 2, 0,16}
{16, 0, 2, 0, 2, 0,16}
{16,16,16,16,16,16,16}
int d[2][DIM];
int i,n=5,m=5,nr_sol=0,nse=0;
void tiparire(int kmint d[2][DIM]){
int h; nr_sol++;#include <stdio.h>
#include <conio.h>
#define N 10
#define M 15
#define DIM (N-1)*(M-1)
int L[N][M]={16,16,16,16,16,16,16}
{16, 0, 2, 1, 1, 0,16}
{16, 0, 2, 0, 8, 0,16}
{16, 0, 2, 4, 8, 0,16}
{16, 1, 7, 4, 2, 0,16}
{16, 0, 2, 0, 2, 0,16}
{16,16,16,16,16,16,16}
int d[2][DIM];
int i,n=5,m=5,nr_sol=0,nse=0;
void tiparire(int kmint d[2][DIM]){
int h; nr_sol++;
printf("\nSolutia %d:\n", nr_sol);
for(h=1,h<=k,h++){
printf("[%d,%d]->",d[0][h],d[1][h]);
if(h%8==0)
printf("\n"); }
printf("\n");
if(nr_sol%nse==0){ printf("\n"); getch; clrscr;
} }
void iesire(int k,int i,int j,int L[N][M], int d[2]2[DIM]){
int gasit, h;
if(L[i][j]==16)
tiparire(k,d);
else{ k++;
d[0][k]=i;
d[1][k]=j;
gasit=0;
for(h=1,h<=k-1;h++)
if(d[0][h]==d[0][k]&&d[1][h]==d[1][k])
gasit=1;
if(!gasit)
for(h=1lh<=4,h++)
switch(h){
case 1:if(L[i][j]&8)
iesire(k,i-1,j,L,d); break;
case 2:if(L[i][j]&4)

iesire(k,i,j+1,L,d); break;
case 3:if(L[i][j]&2)
iesire(k,i+1,j,L,d); break;
case 1:if(L[i][j]&1)
iesire(k,i,j-1,L,d);}
k--;}
}
void main(void){
int il,ic;
clrscr();
printf("Dimensiuni labirint(Matrice),linii, coloane: ")
scanf("%d%d",&n,&m);
for(il=1; il<=n; il++)
for(ic=1; ic<=n; ic++) {
printf("L[%d,%d]=",il,ic);
scanf("%d",&L[il][ic])
}
printf("Punctul de plecare (i,j): ");
scanf("%d%d",&n,&m);
for(ic=1;ic<=m;ic++){
L[0][ic]=16
L[n+1][ic]=16}
for(il=1;il<=m;il++){
L[il][0]=16
L[m+1][il]=16}
for(il=0;il<n;il++){
for(ic=0;ic<m+2;ic++)
if(il==i&&ic==j)
printf("%3d",L[il][ic]);}
printf("Coordonate punct plecare L[%d,%d]=%d\n",nr_sol);
printf("Apasati ENTER pentru a termina programul!");
getch();
}