Skip to content

Commit

Permalink
add a bunch of files
Browse files Browse the repository at this point in the history
  • Loading branch information
witek-formanski committed Jan 10, 2024
1 parent 9aa5a28 commit 6db0870
Show file tree
Hide file tree
Showing 15 changed files with 693 additions and 13 deletions.
31 changes: 31 additions & 0 deletions src/cw12/zad1/kinoman.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
sortujemy po końcach
przeglądamy od najwcześniejszych
*/

#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>

bool compare_second(const std::pair<int, int> &a, const std::pair<int, int> &b) {
return a.second < b.second;
}

int kinoman(std::vector<std::pair<int, int>> teletydzien) {
std::sort(teletydzien.begin(), teletydzien.end(), compare_second);
int liczba_filmow = 0;
int i = 0, j = 1;
while (i < teletydzien.size()) {
liczba_filmow++;
while (teletydzien[j].first <= teletydzien[i].second && j < teletydzien.size())
j++;
i = j++;
}

return liczba_filmow;
}

int main() {
std::cout << kinoman({{1, 5}, {2, 3}, {3, 6}, {4, 7}, {9, 11}}) << "\n";
}
4 changes: 4 additions & 0 deletions src/cw12/zad2/gwozde.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
sortujemy po końcach odcinków
*/
3 changes: 3 additions & 0 deletions src/cw12/zad3/stacje_benzynowe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
tankujemy na ostatniej możliwej stacji zanim skończy nam się paliwo
*/
77 changes: 77 additions & 0 deletions src/cw12/zad4/silnia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
5! = 4 * 4! + 3 * 3! + 2 * 2! + 1 * 1! + 1
5! = 4 * 24 + 18 + 4 + 1 + 1
*/

#include <iostream>
#include <vector>

class Program {
std::vector<int> factorials_map;
std::vector<int> factorial_indexes;

void set_factorials_map(int n) {
if (n < 0)
return;

factorials_map.push_back(1);
int i = 0;

while (factorials_map[i] < n) {
i++;
factorials_map.push_back(factorials_map[i - 1] * i);
}

factorials_map.pop_back();
}

int get_highest_factorial(int n) {
int left = 0;
int right = factorials_map.size() - 1;
int result = -1;

while (left <= right) {
int mid = left + (right - left) / 2;

if (factorials_map[mid] <= n) {
result = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}

return result;
}

void factorials(int n) {
if (!n)
return;

int i = get_highest_factorial(n);
factorial_indexes.push_back(i);
factorials(n - factorials_map[i]);
}

void print() {
for (int factorial : factorial_indexes)
std::cout << factorial << " ";
std::cout << "\n";

for (int factorial : factorial_indexes)
std::cout << factorials_map[factorial] << " ";
std::cout << "\n";
}

public:
Program(int n) {
set_factorials_map(n);
factorials(n);
print();
}
};

int main() {
Program(169);
Program(42);
}
13 changes: 13 additions & 0 deletions src/cw9/zad2/monkeys.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <algorithm>

int* monkeys(int** monkeys, int n) {
int* fallen_monkeys = new int[n];
std::fill(fallen_monkeys, fallen_monkeys + n, -1);
// ustawiamy INT_MAX w małpce nr 1 i we wszystkich małpkach, które się jej trzymają i nie mają podanego czasu puszczenia
//
}

int main() {

}
95 changes: 95 additions & 0 deletions src/cw9/zad5/path.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <queue>
#include <utility>
#include <vector>

class Graph {
public:
typedef std::pair<int, float> edge;

private:
int n_vertices = 0;
std::vector<std::vector<edge>> edges{};

public:
Graph(int n) {
n_vertices = n;
for (int i = 0; i < n; i++) {
edges.push_back(std::vector<edge>{});
}
}
int size() {
return n_vertices;
}

void insert_directed_edge(int v1, int v2, float len) {
edges[v1].push_back(std::make_pair(v2, len));
}

void insert_directed_edge(int v1, int v2) {
insert_directed_edge(v1, v2, 1.0);
}

void insert_edge(int v1, int v2, float len) {
insert_directed_edge(v1, v2, len);
insert_directed_edge(v2, v1, len);
}

void insert_edge(int v1, int v2) {
insert_edge(v1, v2, 1.0);
}

std::vector<edge> neighbours(int v) {
return edges[v];
}

std::vector<std::vector<int>> search() {
std::vector<bool> visited(size(), false);
std::vector<std::vector<int>> result{};
for (int v = 0; v < n_vertices; v++) {
if (!visited[v]) {
std::deque<int> q{v};
std::vector<int> component{};
visited[v] = true;
while (!q.empty()) {
int u = q.front();
q.pop_front();
component.push_back(u);
for (std::pair<int, float> e : neighbours(u)) {
int w = e.first;
if (!visited[w]) {
visited[w] = true;
q.push_back(w);
}
}
}
result.push_back(component);
}
}
return result;
}
};

class CompareDist {
public:
bool operator()(Graph::edge const &e1, Graph::edge const &e2) {
return e1.first > e2.first;
}
};

int get_longest_increasing_path_length(Graph g) {
int next_element;
bool *visited = new bool[g.size()]{false};
// std::pair<path_length, node_number>
std::priority_queue<std::pair<int, int>, CompareDist> path;
// minimal element: 0

for (int i = 0; i < g.size(); i++) {
if (visited[i])
continue;

path.push(std::make_pair(0, 0));
while (!path.empty()) {

}
}
}
90 changes: 77 additions & 13 deletions src/kol3_13/mice_in_the_corridor.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,109 @@
#include <algorithm>
#include <iostream>
#include <cmath>
#include <iostream>

int** get_sum(int mice[], int n) {
int** sum = new int*[n];
for (int i = 0; i < n; i++)
for (int i = 0; i < n; i++) {
sum[i] = new int[n]{0};
sum[i][i] = mice[i];
}

int* prefix_sum = new int[n]{mice[0]};
for (int i = 1; i < n; i++)
prefix_sum[i] = prefix_sum[i - 1] + mice[i];

int* length_coefficient = new int[n];
for (int i = 0; i < n; i++)
sum[i][i] = mice[i];

for (int length = 2; length < n; length++) {
for (int i = 0; i < n - length; i++) {
sum[i][i + length - 1] = sum[i][i+ length - 2] + mice[i + length - 1] - pow(length - 1, 2);
length_coefficient[0] = pow(i + 1, 2);

for (int length = 2; length <= n; length++) {
for (int i = 0; i < n - length + 2; i++) {
sum[i][i + length - 1] = std::max(
sum[i][i + length - 2] + mice[i + length - 1] + (int)pow(length - 2, 2) - (int)pow(length - 1, 2),
0);
}
}

return sum;
}

int** get_max_in_interval(int** sum, int n) {

int** interval_max = new int*[n];
for (int i = 0; i < n; i++) {
interval_max[i] = new int[n]{0};
interval_max[i][i] = sum[i][i];
}

int j;
for (int length = 2; length <= n; length++) {
for (int i = 0; i < n - length + 1; i++) {
j = i + length - 1;
interval_max[i][j] = std::max(
sum[i][j],
std::max(
interval_max[i + 1][j],
interval_max[i][j - 1]));
}
}

return interval_max;
}

void delete_array(int** tab, int n, int m) {
}

void print(int** tab, int n) {
void print(int** tab, int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
for (int j = 0; j < m; j++)
std::cout << tab[i][j] << "\t";
std::cout << "\n";
}
}

int mice_in_the_corridor(int mice[], int n, int k) {
if (k < 1 || k > n)
return -1;

int** dp = new int*[k - 1];
for (int i = 0; i < k - 1; i++) {
dp[i] = new int[n - 1]{0};
}

int** interval_max = get_max_in_interval(get_sum(mice, n), n);

for (int i = 0; i < n - 1; i++) {
dp[0][i] = interval_max[0][i];
// dp[0][i] = interval_max[i + 1][n - 1];
}

int mice_in_the_corridor(int mice[], int n) {
for (int cat = 2; cat < k; cat++)
dp[cat - 1][cat - 1] = dp[cat - 2][cat - 2] + mice[cat - 1];

std::cout << "\n";

for (int cat = 2; cat < k; cat++) {
for (int i = cat - 1; i < n - 1; i++) {
// dp[cat - 1][i] = dp[cat - 2][i];
// dp[cat - 1][i] = interval_max[i + 1][n - 1];
}
// print(dp[cat - 1], 2, n);
std::cout << "\n";
}
// print(dp, k - 1, n);

return 1;
}

int main() {
// print()
int n = 8;
int* mice = new int[8]{1, 5, 1, 4, 3, 2, 7, 0};
print(get_sum(mice, 8), 8);

int** sum = get_sum(mice, n);
// print(sum, n, n);
std::cout << "\n";
int** interval_max = get_max_in_interval(sum, n);
// print(interval_max, n, n);
std::cout << "\n";
int res = mice_in_the_corridor(mice, n, 8);
}
12 changes: 12 additions & 0 deletions src/kol3_23/zad1/rabunek_1d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <vector>

int* init_dp(int k) {
int* dp = new int[k + 1];
std::fill(dp, dp + k + 1, -1);
return dp;
}

int rabunek(std::vector<int> n, int k) {
int* dp = init_dp(k);

}
19 changes: 19 additions & 0 deletions src/kol3_23/zad1/rabunek_2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <vector>

bool** init_dp(int n_size, int k) {
bool** dp = new bool*[k+1];
for (int i = 0; i <= k; i++)
dp[i] = new bool[n_size+1]{false};

dp[0][n_size] = true;
return dp;
}

void delete_dp(bool** dp, int k) {
for (int i = 0; i <= k; i++)
delete[] dp[i];
delete[] dp;
}

int rabunek(std::vector<int> n, int k) {
}
Empty file.
Loading

0 comments on commit 6db0870

Please sign in to comment.