Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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

Lucrare Individuală Nr.1

METODA BRANCH AND BOUND ȘI BRANCH AND CUT


Specialitatea: Programare și analiza produselor program

Elev: Ceban Marian, grupa P-1831 V-3!

Profesor: Dascal Adrian

Chișinău, 2020
Problema 1.
#include <fstream>
using namespace std;
const int DMAX = 500;
ifstream fin("Fisier.in");
ofstream fout("Fisier.out");
// Vectorii de deplasare
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];
// Subprogramul de citire a datelor din fișier
void citeste() {
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;
}
// Subprogramul de a înconjura obstacolele
void inconjoara() {
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;
}
}
}
}
// Subprogramul de afișare a datelor în fișier
void afiseaza() {
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--;
}
}
// Programul principal
int main() {
citeste();
inconjoara();
lee();
afiseaza();
fout.close();
return 0;}
Date de intrare: Date de ieșire:

Vectorul sortat: 14, 19, 28, 32, 33, 37, 54, 61, 84, 87
Poz= start+ (x- A[start])*(finish – start)/A[finish]-A[start]
Poz = 0+(37-14)(9-0)/87-14=2.8
…..
Poz=5+((37-37)*(9-5)/(87-37)=5

You might also like