From 94088aa77903d9d0b77f179e7b6aac2c15607d76 Mon Sep 17 00:00:00 2001 From: z4root Date: Sat, 31 Oct 2026 00:19:47 +0000 Subject: [PATCH 1/4] feat(kata): add the solution with the test --- Katas/CP/nexround/src/solution.cpp | 35 ++++++++++++++++++++++++++++ Katas/CP/nexround/test/expected1.txt | 1 + Katas/CP/nexround/test/input1.txt | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 Katas/CP/nexround/src/solution.cpp create mode 100644 Katas/CP/nexround/test/expected1.txt create mode 100644 Katas/CP/nexround/test/input1.txt diff --git a/Katas/CP/nexround/src/solution.cpp b/Katas/CP/nexround/src/solution.cpp new file mode 100644 index 0000000..e3e6d39 --- /dev/null +++ b/Katas/CP/nexround/src/solution.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +int main() { + std::ios_base::sync_with_stdio(false); + std::cin.tie(NULL); + + int n, k; + std::cin >> n >> k; + int scores[n]; + + for (int i = 0; i < n; i++) { + std::cin >> scores[i]; + } + + int count = 0; + for (int i = 0; i < n; i++) { + if (scores[i] == 0) + break; + else { + if (scores[i] > 0 && i + 1 <= k) { + count++; + } else { + if (scores[i] == scores[k - 1]) { + count++; + } else { + break; + } + } + } + } + std::cout << count << std::endl; + + return 0; +} diff --git a/Katas/CP/nexround/test/expected1.txt b/Katas/CP/nexround/test/expected1.txt new file mode 100644 index 0000000..1e8b314 --- /dev/null +++ b/Katas/CP/nexround/test/expected1.txt @@ -0,0 +1 @@ +6 diff --git a/Katas/CP/nexround/test/input1.txt b/Katas/CP/nexround/test/input1.txt new file mode 100644 index 0000000..ed179c9 --- /dev/null +++ b/Katas/CP/nexround/test/input1.txt @@ -0,0 +1,2 @@ +8 5 +10 9 8 7 7 7 5 5 From 4b73e0dabfbb4012d032d2e5d8e6e5c3a1075396 Mon Sep 17 00:00:00 2001 From: z4root Date: Sat, 31 Oct 2026 00:20:25 +0000 Subject: [PATCH 2/4] feat(kata): add the solution with the test --- Katas/CP/sauSaGebank/src/solution.cpp | 42 ++++++++++++++++++++++++ Katas/CP/sauSaGebank/src/solutionv2 | Bin 0 -> 16520 bytes Katas/CP/sauSaGebank/test/expected1.txt | 5 +++ Katas/CP/sauSaGebank/test/input1.txt | 6 ++++ 4 files changed, 53 insertions(+) create mode 100644 Katas/CP/sauSaGebank/src/solution.cpp create mode 100755 Katas/CP/sauSaGebank/src/solutionv2 create mode 100644 Katas/CP/sauSaGebank/test/expected1.txt create mode 100644 Katas/CP/sauSaGebank/test/input1.txt diff --git a/Katas/CP/sauSaGebank/src/solution.cpp b/Katas/CP/sauSaGebank/src/solution.cpp new file mode 100644 index 0000000..8e56555 --- /dev/null +++ b/Katas/CP/sauSaGebank/src/solution.cpp @@ -0,0 +1,42 @@ +// #include +// #include +// int main() { +// int t, n, k; +// int a = 1; +// int c = 0; +// +// std::cin >> t; +// for (int i = 0; i < t; i++) { +// std::cin >> n >> k; +// for (int j = n; j > 0; j--) { +// if (j >= k) { +// if (j == (n - k)) { +// c += a; +// a = 1; +// k--; +// } else { +// a = pow(2, j); +// } +// } +// } +// std::cout << c << std::endl; +// } +// +// return 0; +// } + +#include +using namespace std; +int main() { + cin.tie(0); + cout.tie(0); + ios_base::sync_with_stdio(0); + int tc; + cin >> tc; + while (tc--) { + int n, k; + cin >> n >> k; + cout << (1 << (n - k + 1)) + 2 * (k - 1) << '\n'; + } + return 0; +} diff --git a/Katas/CP/sauSaGebank/src/solutionv2 b/Katas/CP/sauSaGebank/src/solutionv2 new file mode 100755 index 0000000000000000000000000000000000000000..d87bdc2ed85a4fa36aae41e8ad2dffecce0fe246 GIT binary patch literal 16520 zcmeHOYiu0V6~4QU6Nfy!Ax>)&nrxz^a!NDVwG-Ds-Hh$5Ge&vg2TCb08Sk#`Y4+jn zj)P4>wGv=P^CVlDuM#G2(2k8N?V%kIrpBk zo*i~ugw+0M=Ss8Zp6@*Foilf4?%g@}OR>GZ!9YN8sS}?O$ej!+L?^+E9aI6Liw@BU zzZ=AQu^9M85>s+r5s<24)K$_3!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7bkPwD^&B@)P!SaGuqKsEj~VuolIsD*hSOq?eE$b zGh_RAW1hbW&q6b15NPb~7v}EI?(f>y*CWh5dk=JX?KKbd_721b&B3njy)m#zCM?H- zO#laE0)EDv$R`v3K1*MhN$x6}9a?p#&MOgQ!ei1qrPe3%S#!+FByhVyd3!*m4-5}@ z@}%XLok21^S~?#v_rKD&C;Pwb6nx^g0%#U?L~sZ{%%+FR=D>s8c2J3$7-+TQ0HU6O zAe+PaJOf};Ytw_<4elJkILKWUZo$9a;z7GFDh;Y^5vjTjL}>Y`v||keb#jW1aV?W| zlGMn0H~W$nEp|nQ03tbGtlmWgj|J7QR|6%&&Q#Ei*Jh2dClK zHrw+&*8mLXsN6o!*O~JC98_fS_WvNDI2UGnp8qmkPj=jY)?<1*$Z>AXJkPJ0j*~t1 zA9c9@1d9|@&^O!j{GRDNDRTR4&*y)X?7K;i*9%Nfy6n-$Yd;Mb#)Q{5<#|8|Kq$P9 zQk?25*O7h^4!3=n?3j+bm7z}JGQHnp&+`_hZ+b2m+q2t;JoY?)V#@18*5^1f{|MQa z=N4g-5cTRa&-4kh=j+GwSf-oF9TT=={NtojJ zau=`t84$XkACZkpo2l+LhPv1O=YYBGdHusQ?6LQr|L;H!vv7G2qblzo<9(>!_Lyh- z2G}&Z?0J2EdK-Fse}CDI={ul&ynn%XDzGS2qi=LeoE7B}@YA?1h3VVDNY#{k89l+T-=e@g-5zDq;;nZ^Y( alr0`1x2vSM7N~CjjZZ0!^&SHcEB*=JY)&Bn literal 0 HcmV?d00001 diff --git a/Katas/CP/sauSaGebank/test/expected1.txt b/Katas/CP/sauSaGebank/test/expected1.txt new file mode 100644 index 0000000..884dbe8 --- /dev/null +++ b/Katas/CP/sauSaGebank/test/expected1.txt @@ -0,0 +1,5 @@ +2 +4 +8 +10 +514 diff --git a/Katas/CP/sauSaGebank/test/input1.txt b/Katas/CP/sauSaGebank/test/input1.txt new file mode 100644 index 0000000..285ea26 --- /dev/null +++ b/Katas/CP/sauSaGebank/test/input1.txt @@ -0,0 +1,6 @@ +5 +1 1 +2 1 +4 3 +5 5 +10 2 From 10cf2acecf58b7fd8d6e36492198c8710d584217 Mon Sep 17 00:00:00 2001 From: z4root Date: Sat, 31 Oct 2026 00:21:08 +0000 Subject: [PATCH 3/4] feat(algorithms): add the explanation of greedy algorithm --- Katas/Algorithms/greedy/Greedy.md | 13 +++++++++ .../greedy/example/src/solution.cpp | 28 +++++++++++++++++++ .../greedy/example/test/expected1.txt | 1 + .../Algorithms/greedy/example/test/input1.txt | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 Katas/Algorithms/greedy/Greedy.md create mode 100644 Katas/Algorithms/greedy/example/src/solution.cpp create mode 100644 Katas/Algorithms/greedy/example/test/expected1.txt create mode 100644 Katas/Algorithms/greedy/example/test/input1.txt diff --git a/Katas/Algorithms/greedy/Greedy.md b/Katas/Algorithms/greedy/Greedy.md new file mode 100644 index 0000000..8de2ffd --- /dev/null +++ b/Katas/Algorithms/greedy/Greedy.md @@ -0,0 +1,13 @@ +# Greedy + +Greedy is an algorithmic paradigm that builds a problem piece by piece, choosing in that moment the next piece that seems more efficient. + +Don't use the divide and conquer; we go right away to the answer, and we make the best decision at the moment. Regardless of the future, don't be the best. + +###### _Example:_ + +- [Coin Example](./example/src/solution.cpp) + +###### **Katas:** + +- [2276A Perfect Sandwiches](../../CP/perfect_sanduches/src/solution.cpp) diff --git a/Katas/Algorithms/greedy/example/src/solution.cpp b/Katas/Algorithms/greedy/example/src/solution.cpp new file mode 100644 index 0000000..17d90b5 --- /dev/null +++ b/Katas/Algorithms/greedy/example/src/solution.cpp @@ -0,0 +1,28 @@ +#include +int main() { + + int n; + int amount; + std::cin >> n >> amount; + int coins[n]; + int rest = 0; + for (int i = 0; i < n; i++) { + std::cin >> coins[i]; + } + + for (int i = n - 1; i >= 0; i--) { + if (amount >= coins[i]) { + int cnt = (amount / coins[i]); + rest += cnt; + amount -= (cnt * coins[i]); + } + + if (amount == 0) { + break; + } + } + + std::cout << rest << std::endl; + + return 0; +} diff --git a/Katas/Algorithms/greedy/example/test/expected1.txt b/Katas/Algorithms/greedy/example/test/expected1.txt new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/Katas/Algorithms/greedy/example/test/expected1.txt @@ -0,0 +1 @@ +3 diff --git a/Katas/Algorithms/greedy/example/test/input1.txt b/Katas/Algorithms/greedy/example/test/input1.txt new file mode 100644 index 0000000..bb54689 --- /dev/null +++ b/Katas/Algorithms/greedy/example/test/input1.txt @@ -0,0 +1,2 @@ +3 20 +1 10 18 From 88273397e0599ba5c6c571c9a4c0888d47b692aa Mon Sep 17 00:00:00 2001 From: z4root Date: Sat, 31 Oct 2026 00:21:58 +0000 Subject: [PATCH 4/4] docs(readme): add the section greedy --- Katas/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Katas/README.md b/Katas/README.md index 138c8c0..c16ee59 100644 --- a/Katas/README.md +++ b/Katas/README.md @@ -1 +1,7 @@ -# 2 codeforces and contest +# Code forces + +I share my logic and my mistakes + +### TOPICS + +- [Greedy](./Algorithms/greedy/Greedy.md)