0% found this document useful (0 votes)
68 views5 pages

Evaluare: Utilizarea Tehnicilor Clasice de Programare

The document contains 3 programming problems involving classic programming techniques: 1. A problem involving a Lee algorithm to find the shortest path between two points in a matrix. 2. No details are provided about the second problem. 3. A problem involving a backtracking algorithm to generate all possible solutions to the N-queens problem and check if positions are valid without any queens attacking each other.

Uploaded by

Denis Budurin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views5 pages

Evaluare: Utilizarea Tehnicilor Clasice de Programare

The document contains 3 programming problems involving classic programming techniques: 1. A problem involving a Lee algorithm to find the shortest path between two points in a matrix. 2. No details are provided about the second problem. 3. A problem involving a backtracking algorithm to generate all possible solutions to the N-queens problem and check if positions are valid without any queens attacking each other.

Uploaded by

Denis Budurin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MINISTERUL EDUCAȚIEI, CULTURII ȘI CERCETĂRII AL REPUBLICII MOLDOVA

IP CENTRUL DE EXCELENȚĂ ÎN INFORMATICĂ ȘI TEHNOLOGII INFORMAȚIONALE

DISCIPLINA

UTILIZAREA TEHNICILOR CLASICE DE PROGRAMARE

Evaluare

Specialitatea: Programare și analiza produselor program

Elev: Budurin Denis, grupa P-1833

Profesor: Dascal Andrian

Chișinău, 2019
Problema 1

Rezolvare:
#include <fstream>
using namespace std;

const int DMAX = 618;

ifstream fin("lee.in");
ofstream fout("lee.out");

const int addLin[] = {-1, 0, 1, 0};


const int addCol[] = {0, 1, 0, -1};

struct Pos {
int lin, col;
};

Pos a, b;
int m, n;
int mat[DMAX][DMAX];

int in, sf;


Pos q[DMAX * DMAX];

int vf;
Pos st[DMAX * DMAX];

void scan() {
fin >> m >> n;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
fin >> mat[i][j];
fin >> a.lin >> a.col;
fin >> b.lin >> b.col;
}

void surround() {
for (int i = 0; i <= m + 1; i++)
mat[i][0] = mat[i][n + 1] = -1;
for (int j = 1; j <= n; j++)
mat[0][j] = mat[m + 1][j] = -1;
}

void lee() {
q[0] = a;
in = sf = 0;
mat[a.lin][a.col] = 1;

Pos pos;
while (in <= sf && !mat[b.lin][b.col]) {
pos = q[in++];
for (int k = 0; k < 4; k++) {
Pos ngh;
ngh.lin = pos.lin + addLin[k];
ngh.col = pos.col + addCol[k];

if (!mat[ngh.lin][ngh.col]) {
mat[ngh.lin][ngh.col] = mat[pos.lin][pos.col] + 1;
q[++sf] = ngh;
}
}
}
}

void print() {
Pos pos = st[++vf] = b;
while (mat[pos.lin][pos.col] > 1)
for (int k = 0; k < 4; k++) {
Pos ngh;
ngh.lin = pos.lin + addLin[k];
ngh.col = pos.col + addCol[k];

if (mat[ngh.lin][ngh.col] == mat[pos.lin][pos.col] - 1) {
st[++vf] = pos = ngh;
break;
}
}

fout << mat[b.lin][b.col] << '\n';


while (vf) {
fout << st[vf].lin << ' ' << st[vf].col << '\n';
vf--;
}
}

int main() {
scan();
surround();

lee();
print();

fout.close();
return 0;
}
Lee.in:
Lee.out:

11
12
13
14
15
16
26
36
46
47
48
49
4 10
5 10
6 10
7 10
7 10

Problema 2

Problema 3
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
int n,v[100],sol;
void afisare()
{int i,j,x;
sol++;
cout<<"\n Solutia: "<<sol<<'\n';
for (i=1;i<=n;i++)
{for (j=1;j<=n;j++)
if (v[i]==j) cout<<"T";
else cout<<"_ ";
cout<<'\n';
}
}
//Subprograma valid controleaza daca damele se intersecteaza pe linii,coloane sau
diagonale
int valid(int k)
{int i;
for (i=1;i<=k-1;i++)
if ((v[i]==v[k]))
return 0;
return 1;}
int solutie(int k)
{if (k==n)
return 1;
return 0;}
//Subprograma bk este folosita pentru a controla daca damele nu se intersecteaza,si a
afisa rezultatele
void BK(int k)
{int i;
for (i=1;i<=n;i++)
{v[k]=i;
if (valid(k)==1)
{if (solutie(k)==1)
afisare();
else
BK(k+1);
}
}
}
int main()
{cout<<"n= ";cin>>n;
BK(1);
}

You might also like