diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac99c17 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# USACO Practice +[![Build Status](https://drone.adawesome.tech/api/badges/abheekd/usaco-practice/status.svg)](https://drone.adawesome.tech/abheekd/usaco-practice) +### Coded in C++. +Currently I'm not very good so I'm practicing low-level and/or Bronze questions. \ No newline at end of file diff --git a/codeforces/Caps Lock/index.cpp b/codeforces/Caps Lock/index.cpp index cd5c1bc..a11b343 100644 --- a/codeforces/Caps Lock/index.cpp +++ b/codeforces/Caps Lock/index.cpp @@ -1,7 +1,6 @@ -using namespace std; - #include #include +using namespace std; string parseString(string n) { string m = n; diff --git a/codeforces/Next Round/index.cpp b/codeforces/Next Round/index.cpp index 3a9e24e..8029238 100644 --- a/codeforces/Next Round/index.cpp +++ b/codeforces/Next Round/index.cpp @@ -1,6 +1,5 @@ -using namespace std; - #include +using namespace std; int main() { int n, k; diff --git a/codeforces/Soldier and Bananas/index.cpp b/codeforces/Soldier and Bananas/index.cpp index 71bb126..87f2101 100644 --- a/codeforces/Soldier and Bananas/index.cpp +++ b/codeforces/Soldier and Bananas/index.cpp @@ -1,6 +1,5 @@ -using namespace std; - #include +using namespace std; int main() { int k, n, total_cost; diff --git a/codeforces/Team/index.cpp b/codeforces/Team/index.cpp index 746b9e0..387c3b6 100644 --- a/codeforces/Team/index.cpp +++ b/codeforces/Team/index.cpp @@ -1,6 +1,5 @@ -using namespace std; - #include +using namespace std; int main() { int n; diff --git a/codeforces/Watermelon/index.cpp b/codeforces/Watermelon/index.cpp index fbc4c75..1799dae 100644 --- a/codeforces/Watermelon/index.cpp +++ b/codeforces/Watermelon/index.cpp @@ -1,6 +1,5 @@ -using namespace std; - #include +using namespace std; int main() { int n; diff --git a/codeforces/Way Too Long Words/index.cpp b/codeforces/Way Too Long Words/index.cpp index 767eb26..993613c 100644 --- a/codeforces/Way Too Long Words/index.cpp +++ b/codeforces/Way Too Long Words/index.cpp @@ -1,7 +1,6 @@ -using namespace std; - #include #include +using namespace std; int main() { int n; diff --git a/test.sh b/test.sh index 79cc92d..3329a5f 100755 --- a/test.sh +++ b/test.sh @@ -4,4 +4,6 @@ FILES=*/*/*.cpp for f in $FILES do gcc "$f" -lstdc++ -o /dev/null + status=$? + [ $status -eq 0 ] && echo "$f was compiled successfully" || echo "Compilation of $f failed" done diff --git a/usaco/Breed Counting/index.cpp b/usaco/Breed Counting/index.cpp new file mode 100644 index 0000000..03a787a --- /dev/null +++ b/usaco/Breed Counting/index.cpp @@ -0,0 +1,33 @@ +#include +#include +using namespace std; + +int main() { + freopen("bcount.in", "r", stdin); + freopen("bcount.out", "w", stdout); + int n, q; + cin >> n >> q; + int cow_array[n]; + for (int i = 0; i < n; i++) { + int j; + cin >> j; + cow_array[i] = j; + } + for (int i = 0; i < q; i++) { + int j, k; + cin >> j >> k; + int a = 0; + int b = 0; + int c = 0; + for (int i = 0; i < abs(j - k) + 1; i++) { + if (cow_array[i + j - 1] == 1) { + a++; + } else if (cow_array[i + j - 1] == 2) { + b++; + } else if (cow_array[i + j - 1] == 3) { + c++; + } + } + cout << a << " " << b << " " << c << endl; + } +} diff --git a/usaco/Mixing Milk/index.cpp b/usaco/Mixing Milk/index.cpp new file mode 100644 index 0000000..56d21ff --- /dev/null +++ b/usaco/Mixing Milk/index.cpp @@ -0,0 +1,68 @@ +#include +using namespace std; + +int main() { + freopen("mixmilk.in", "r", stdin); + freopen("mixmilk.out", "w", stdout); + + int a_cap, a_val; + cin >> a_cap >> a_val; + int b_cap, b_val; + cin >> b_cap >> b_val; + int c_cap, c_val; + cin >> c_cap >> c_val; + + for (int i = 0; i < 33; i++) { + int a_diff, b_diff, c_diff; + a_diff = abs(a_cap - a_val); + b_diff = abs(b_cap - b_val); + c_diff = abs(c_cap - c_val); + + if (b_diff >= a_val) { + b_val += a_val; + a_val = 0; + } else { + b_val = b_cap; + a_val -= b_diff; + } + a_diff = abs(a_cap - a_val); + b_diff = abs(b_cap - b_val); + c_diff = abs(c_cap - c_val); + + if (c_diff >= b_val) { + c_val += b_val; + b_val = 0; + } else { + c_val = c_cap; + b_val -= c_diff; + } + a_diff = abs(a_cap - a_val); + b_diff = abs(b_cap - b_val); + c_diff = abs(c_cap - c_val); + + if (a_diff >= c_val) { + a_val += c_val; + c_val = 0; + } else { + a_val = a_cap; + c_val -= a_diff; + } + a_diff = abs(a_cap - a_val); + b_diff = abs(b_cap - b_val); + c_diff = abs(c_cap - c_val); + } + int a_diff, b_diff, c_diff; + a_diff = abs(a_cap - a_val); + b_diff = abs(b_cap - b_val); + c_diff = abs(c_cap - c_val); + + if (b_diff >= a_val) { + b_val += a_val; + a_val = 0; + } else { + b_val = b_cap; + a_val -= b_diff; + } + + cout << a_val << endl << b_val << endl << c_val << endl; +} diff --git a/usaco/Mixing Milk/mixmilk.in b/usaco/Mixing Milk/mixmilk.in new file mode 100644 index 0000000..b74be8d --- /dev/null +++ b/usaco/Mixing Milk/mixmilk.in @@ -0,0 +1,3 @@ +10 3 +11 4 +12 5 diff --git a/usaco/Mixing Milk/mixmilk.out b/usaco/Mixing Milk/mixmilk.out new file mode 100644 index 0000000..c2a9177 --- /dev/null +++ b/usaco/Mixing Milk/mixmilk.out @@ -0,0 +1,3 @@ +0 +10 +2 diff --git a/usaco/Shell Game/index.cpp b/usaco/Shell Game/index.cpp new file mode 100644 index 0000000..ef1da8b --- /dev/null +++ b/usaco/Shell Game/index.cpp @@ -0,0 +1,40 @@ +#include +#include +using namespace std; + +int main() { + freopen("shell.in", "r", stdin); + freopen("shell.out", "w", stdout); + + int n; + cin >> n; + + int score = 0; + + int a_values[n]; + int b_values[n]; + int g_values[n]; + for (int i = 0; i < n; i++) { + cin >> a_values[i] >> b_values[i] >> g_values[i]; + } + int shell_num; + shell_num = 0; + for (int i = 0; i < 3; i++) { + shell_num = i + 1; + for (int j = 0; j < n; j++) { + int a, b, g; + a = a_values[i]; + b = b_values[i]; + g = g_values[i]; + if (a == shell_num) { + shell_num = b; + } else if (b == shell_num) { + shell_num = a; + } + if (g == shell_num) { + score++; + } + } + } + cout << score << endl; +} diff --git a/usaco/Shell Game/shell.out b/usaco/Shell Game/shell.out new file mode 100644 index 0000000..e69de29 diff --git a/usaco/Teleportation/index.cpp b/usaco/Teleportation/index.cpp index 001895e..842f4e0 100644 --- a/usaco/Teleportation/index.cpp +++ b/usaco/Teleportation/index.cpp @@ -1,15 +1,16 @@ #include +using namespace std; int a, b, x, y; int main() { - std::cin >> a >> b >> x >> y; + cin >> a >> b >> x >> y; int path1; int path2; int path3; int ans; - path1 = std::abs(a - b); - path2 = std::abs(a - x) + std::abs(y - b); - path3 = std::abs(a - y) + std::abs(x - b); + path1 = abs(a - b); + path2 = abs(a - x) + abs(y - b); + path3 = abs(a - y) + abs(x - b); ans = path1; if (path2 < ans) { ans = path2; @@ -17,5 +18,5 @@ int main() { if (path3 < ans) { ans = path3; } - std::cout << ans << std::endl; + cout << ans << endl; }