-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8f197e
commit 6ea9f93
Showing
83 changed files
with
5,038 additions
and
0 deletions.
There are no files selected for viewing
Binary file removed
BIN
-1.53 MB
Sem IV/Algoritmi Avansati/Curs/Algoritmi Avansati 2021 c-5(Alg Genetici TAP).pdf
Binary file not shown.
Binary file added
BIN
+775 KB
...V/Algoritmi Avansati/Curs/Algoritmi Avansați 2021 c-10 Triangularea_Multimilor_Puncte.pdf
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.32 MB
Sem IV/Algoritmi Avansati/Curs/Algoritmi Avansați 2021 c-8 Acoperiri_Convexe.pdf
Binary file not shown.
Binary file added
BIN
+1.44 MB
Sem IV/Algoritmi Avansati/Curs/Algoritmi Avansați 2021 c-9_10 Triangularea_poligoanelor.pdf
Binary file not shown.
Binary file added
BIN
+2.69 KB
Sem IV/Algoritmi Avansati/Lab/lab5/lab5_HorjeaCosminMarian_2431_ex34.zip
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef pair<double, double> point; | ||
|
||
double testTurn(point p, point q, point r) | ||
{ | ||
double a = q.first * r.second; | ||
a += p.second * r.first; | ||
a += p.first * q.second; | ||
a -= q.first * p.second; | ||
a -= p.first * r.second; | ||
a -= q.second * r.first; | ||
return a; | ||
} | ||
ostream &operator<<(ostream &out, point x) | ||
{ | ||
out << x.first << " " << x.second; | ||
return out; | ||
} | ||
void isInside(vector<point> poligon, point p) | ||
{ | ||
int countIntersections = 0; | ||
int n = poligon.size(); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
int j = (i + 1) % n; | ||
if (p.first == poligon[i].first && p.second == poligon[i].second) | ||
{ | ||
cout << "Punctul " + to_string(p.first) + " " + to_string(p.second) + " este un punct care formeaza poligonul\n"; | ||
return; | ||
} | ||
if (p.second == poligon[i].second && p.second == poligon[j].second) | ||
{ | ||
// daca e o linie orizontala verificam daca ne aflam pe ea | ||
if (p.first > min(poligon[i].first, poligon[j].first) && p.first < max(poligon[i].first, poligon[j].first)) | ||
{ | ||
//testam sa vedem daca ne aflam pe linie | ||
// cout << "Punctul " + to_string(p.first) + " " + to_string(p.second) + " este pe linia poligonului\n"; | ||
cout << setw(3) << p << " Se afla pe o latura a poligonului\n"; | ||
return; | ||
} | ||
} | ||
if ((p.first < poligon[i].first || | ||
p.first < poligon[j].first) && | ||
p.second >= min(poligon[i].second, poligon[j].second) && // daca trec printr-un punct, il iau in considerare doar daca este in josul laturii | ||
p.second < max(poligon[i].second, poligon[j].second)) | ||
{ | ||
// cout << "pentru linia " << i << " avem\n"; | ||
// cout << "Punctele \n"; | ||
// cout << poligon[i] << endl; | ||
// cout << poligon[j] << endl; | ||
countIntersections++; | ||
} | ||
} | ||
// cout << setw(3) << p << " " << countIntersections << setw(10); | ||
cout << setw(3) << p << " " << setw(10); | ||
if (countIntersections % 2) | ||
cout << " Se afla in interior"; | ||
else | ||
cout << " Se afla in exterior"; | ||
cout << endl; | ||
return; | ||
} | ||
int main() | ||
{ | ||
int n; | ||
double x, y; | ||
vector<point> poligon; | ||
vector<point> tests; | ||
// ifstream f("ex1_nu_din_enunt.in"); | ||
// am facut un model putin diferit in care sa testez alte cazuri | ||
// http://prntscr.com/12xep58 | ||
// https://www.geogebra.org/calculator/cen9ybnj | ||
|
||
ifstream f("ex1.in"); | ||
f >> n; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
f >> x >> y; | ||
poligon.push_back({x, y}); | ||
} | ||
while (f >> x >> y) | ||
{ | ||
tests.push_back({x, y}); | ||
} | ||
for (point p : tests) | ||
isInside(poligon, p); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
12 | ||
0 6 | ||
0 0 | ||
6 0 | ||
6 6 | ||
2 6 | ||
2 2 | ||
4 2 | ||
4 5 | ||
5 5 | ||
5 1 | ||
1 1 | ||
1 6 | ||
3 4 | ||
7 3 | ||
3 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
13 | ||
0 6 | ||
0 0 | ||
6 0 | ||
8 2 | ||
6 6 | ||
2 6 | ||
2 3 | ||
4 2 | ||
4 5 | ||
5 5 | ||
5 1 | ||
1 1 | ||
1 6 | ||
3 4 | ||
7 3 | ||
3 2 | ||
3 3 | ||
-2 2 | ||
0.5 2 | ||
6 2 | ||
-1 6 | ||
-1 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef pair<double, double> point; | ||
|
||
double testTurn(point p, point q, point r) | ||
{ | ||
double a = q.first * r.second; | ||
a += p.second * r.first; | ||
a += p.first * q.second; | ||
a -= q.first * p.second; | ||
a -= p.first * r.second; | ||
a -= q.second * r.first; | ||
return a; | ||
} | ||
ostream &operator<<(ostream &out, point x) | ||
{ | ||
out << x.first << " " << x.second; | ||
return out; | ||
} | ||
|
||
void test_monotonicity(vector<point> &polygon) | ||
{ | ||
// prima data x monoton | ||
int left_most = 0; | ||
int n = polygon.size(); | ||
for (int i = 1; i < n; i++) | ||
{ | ||
if (polygon[i].first < polygon[left_most].first) | ||
{ | ||
left_most = i; | ||
} | ||
} | ||
int currentPoint = left_most; | ||
int nextPoint; | ||
int okX = 1; | ||
int increasing = 1; // prima data ne uitam dupa puncte care cres si punctele pot sa scada doar o singura data | ||
for (int i = 0; i < n - 1; i++) | ||
{ | ||
nextPoint = (currentPoint + 1) % n; | ||
|
||
if (polygon[nextPoint].first > polygon[currentPoint].first && !increasing) | ||
{ | ||
okX = 0; | ||
} | ||
if (polygon[nextPoint].first < polygon[currentPoint].first) | ||
{ | ||
if (increasing) | ||
increasing = 0; | ||
} | ||
currentPoint = nextPoint; | ||
} | ||
if (!okX) | ||
{ | ||
cout << "Poligonul nu este x-monoton\n"; | ||
} | ||
else | ||
{ | ||
cout << "Poligonul este x-monoton\n"; | ||
} | ||
// acum cu y monoton | ||
int lowest = 0; | ||
for (int i = 1; i < n; i++) | ||
{ | ||
if (polygon[i].second < polygon[lowest].second) | ||
{ | ||
lowest = i; | ||
} | ||
} | ||
currentPoint = lowest; | ||
int okY = 1; | ||
increasing = 1; | ||
for (int i = 0; i < n - 1; i++) | ||
{ | ||
nextPoint = (currentPoint + 1) % n; | ||
|
||
if (polygon[nextPoint].second > polygon[currentPoint].second && !increasing) | ||
{ | ||
okY = 0; | ||
} | ||
if (polygon[nextPoint].second < polygon[currentPoint].second) | ||
{ | ||
if (increasing) | ||
increasing = 0; | ||
} | ||
currentPoint = nextPoint; | ||
} | ||
if (okY) | ||
{ | ||
cout << "Poligonul este y-monoton\n"; | ||
} | ||
else | ||
{ | ||
cout << "Poligonul nu este y-monoton\n"; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
double x, y; | ||
|
||
ifstream f("ex2.in"); | ||
int nr = 1; | ||
while (f >> n) | ||
{ | ||
vector<point> polygon; | ||
cout << "Poligon " << nr++ << endl; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
f >> x >> y; | ||
polygon.push_back({x, y}); | ||
} | ||
test_monotonicity(polygon); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
6 | ||
4 5 | ||
5 7 | ||
5 9 | ||
2 5 | ||
4 2 | ||
6 3 | ||
8 | ||
8 7 | ||
7 5 | ||
4 5 | ||
3 9 | ||
0 1 | ||
5 2 | ||
3 3 | ||
10 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef pair<double, double> point; | ||
|
||
double testTurn(point p, point q, point r) | ||
{ | ||
double a = q.first * r.second; | ||
a += p.second * r.first; | ||
a += p.first * q.second; | ||
a -= q.first * p.second; | ||
a -= p.first * r.second; | ||
a -= q.second * r.first; | ||
return a; | ||
} | ||
|
||
double detTheta(point A, point B, point C, point D) | ||
{ | ||
vector<vector<double>> tetha = {{A.first, A.second, pow(A.first, 2) + pow(A.second, 2), 1}, | ||
{B.first, B.second, pow(B.first, 2) + pow(B.second, 2), 1}, | ||
{C.first, C.second, pow(C.first, 2) + pow(C.second, 2), 1}, | ||
{D.first, D.second, pow(D.first, 2) + pow(D.second, 2), 1}}; | ||
|
||
for (int i = 0; i < 4; i++) | ||
{ | ||
for (int j = 0; j < 4; j++) | ||
{ | ||
cout << tetha[i][j] << ' '; | ||
} | ||
cout << endl; | ||
} | ||
vector<vector<double>> tethaPrime; | ||
for (int linie = 1; linie < 4; linie++) | ||
{ | ||
tethaPrime.push_back({}); | ||
for (int col = 0; col < 3; col++) | ||
{ | ||
tetha[linie][col] -= tetha[0][col]; | ||
tethaPrime[linie - 1].push_back(tetha[linie][col]); | ||
} | ||
} | ||
double determinant = 0; | ||
determinant += tethaPrime[0][0] * tethaPrime[1][1] * tethaPrime[2][2]; | ||
determinant += tethaPrime[0][1] * tethaPrime[1][2] * tethaPrime[2][0]; | ||
determinant += tethaPrime[1][0] * tethaPrime[2][1] * tethaPrime[0][2]; | ||
determinant -= tethaPrime[0][2] * tethaPrime[1][1] * tethaPrime[2][0]; | ||
determinant -= tethaPrime[0][1] * tethaPrime[1][0] * tethaPrime[2][2]; | ||
determinant -= tethaPrime[2][1] * tethaPrime[1][2] * tethaPrime[0][0]; | ||
return -determinant; | ||
} | ||
|
||
int main() | ||
{ | ||
int x, y; | ||
point D; | ||
vector<point> puncte; | ||
ifstream f("ex3.in"); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
f >> x >> y; | ||
puncte.push_back({x, y}); | ||
} | ||
vector<int> pos = {0, 1, 2}; | ||
while (testTurn(puncte[pos[0]], puncte[pos[1]], puncte[pos[2]]) < 0) | ||
{ | ||
next_permutation(pos.begin(), pos.end()); | ||
} | ||
f >> D.first >> D.second; | ||
if (detTheta(puncte[pos[0]], puncte[pos[1]], puncte[pos[2]], D) < 0) | ||
{ | ||
cout << "D nu este in cerc"; | ||
} | ||
else | ||
{ | ||
cout << "D este in cerc"; | ||
} | ||
f.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
4 2 | ||
2 4 | ||
6 6 | ||
2 2 |
Oops, something went wrong.