-
Notifications
You must be signed in to change notification settings - Fork 1
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
6db0870
commit 5e8cdd9
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
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,11 @@ | ||
/* | ||
pary (d, k) | ||
posortować po k/d | ||
n*log(n) | ||
*/ | ||
|
||
#include <vector> | ||
|
||
std::vector<int> twitter(std::vector<std::pair<int, int>> elon_musks_debts) { | ||
|
||
} |
Empty file.
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,53 @@ | ||
/* | ||
nieparzysta liczba nawiasów => -1 (nie da się) | ||
parzysta liczba nawisów: | ||
suma prefiksowa (+1 za "(", -1 za ")") | ||
docelowo nigdy nie możemy zejść poniżej 0 | ||
l to ostatnia wartość w tablicy prefiksowej | ||
k to maksymalna "głębokość" poniżej osi (-k to min z tablicy prefiksowej) | ||
musimy wykonać sufit z k/2 obróceń od lewej (")" -> "("), żeby nic nie było pod osią | ||
potem musimy wykonać (l + 2suf(k/2))/2 = l/2 + suf(k/2) kroków, żeby ostatnia wartość wynosiła 0 | ||
czyli ostatecznie odpowiedź to l/2 + 2sufit(k/2) | ||
jeżeli k jest ujemne (-k dodatnie), to pomijamy (czyli odp to l/2) | ||
*/ | ||
|
||
/* | ||
parentheses: | ||
( -> 1 | ||
) -> -1 | ||
*/ | ||
|
||
/* | ||
T(n) = O(n) | ||
M(n) = O(n) (można O(1)) | ||
*/ | ||
|
||
#include <algorithm> | ||
|
||
int* get_prefix_tab(int parentheses[], int size) { | ||
int* prefix_tab = new int[size]; | ||
prefix_tab[0] = parentheses[0]; | ||
for (int i = 1; i < size; i++) | ||
prefix_tab[i] = prefix_tab[i - 1] + parentheses[i]; | ||
|
||
return prefix_tab; | ||
} | ||
|
||
int get_minimum(int prefix_tab[], int size) { | ||
int minimum = 0; | ||
for (int i = 0; i < size; i++) | ||
minimum = std::min(minimum, prefix_tab[i]); | ||
} | ||
|
||
int rotate_parentheses(int parentheses[], int size) { | ||
if (size % 2) | ||
return -1; | ||
|
||
int* prefix_tab = get_prefix_tab(parentheses, size); | ||
int minus_k = get_minimum(prefix_tab, size); | ||
int l = prefix_tab[size - 1]; | ||
delete[] prefix_tab; | ||
|
||
return l/2 + 2 * ((-minus_k+1) / 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,8 @@ | ||
/* | ||
system Zeckendorfa | ||
(każda liczba ma dokładnie jedną reprezentację | ||
w niesąsiadujących ze sobą liczbach Fibonacciego) | ||
algorytm: w każdym kroku bierzemy największy możliwy wyraz ciągu Fib | ||
i redukujemy do kolejnego identycznego podproblemu | ||
*/ |
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,17 @@ | ||
/* | ||
analogicznie do nawiasów | ||
odpowiedź to zbiór maksymalnych głębokości sufiksowych | ||
*/ | ||
|
||
#include <vector> | ||
|
||
std::vector<int> get_union(std::vector<int> possible_stations_left, std::vector<int> possible_stations_right) {} | ||
|
||
std::vector<int> get_possible_initial_stations(int distance[], int fuel[], int size, bool direction) {} | ||
|
||
std::vector<int> get_possible_initial_stations(int distance[], int fuel[], int size) { | ||
return get_union( | ||
get_possible_initial_stations(distance, fuel, size, true), | ||
get_possible_initial_stations(distance, fuel, size, false) | ||
); | ||
} |