Browse Source

Merge branch 'master' of https://git.adawesome.tech/abheekd/usaco-practice

square-pasture
Abheek Dhawan 3 years ago
parent
commit
5132c9de41
  1. 4
      README.md
  2. 3
      codeforces/Caps Lock/index.cpp
  3. 3
      codeforces/Next Round/index.cpp
  4. 3
      codeforces/Soldier and Bananas/index.cpp
  5. 3
      codeforces/Team/index.cpp
  6. 3
      codeforces/Watermelon/index.cpp
  7. 3
      codeforces/Way Too Long Words/index.cpp
  8. 2
      test.sh
  9. 33
      usaco/Breed Counting/index.cpp
  10. 68
      usaco/Mixing Milk/index.cpp
  11. 3
      usaco/Mixing Milk/mixmilk.in
  12. 3
      usaco/Mixing Milk/mixmilk.out
  13. 40
      usaco/Shell Game/index.cpp
  14. 0
      usaco/Shell Game/shell.out
  15. 11
      usaco/Teleportation/index.cpp

4
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.

3
codeforces/Caps Lock/index.cpp

@ -1,7 +1,6 @@
using namespace std;
#include <iostream>
#include <string>
using namespace std;
string parseString(string n) {
string m = n;

3
codeforces/Next Round/index.cpp

@ -1,6 +1,5 @@
using namespace std;
#include <iostream>
using namespace std;
int main() {
int n, k;

3
codeforces/Soldier and Bananas/index.cpp

@ -1,6 +1,5 @@
using namespace std;
#include <iostream>
using namespace std;
int main() {
int k, n, total_cost;

3
codeforces/Team/index.cpp

@ -1,6 +1,5 @@
using namespace std;
#include <iostream>
using namespace std;
int main() {
int n;

3
codeforces/Watermelon/index.cpp

@ -1,6 +1,5 @@
using namespace std;
#include <iostream>
using namespace std;
int main() {
int n;

3
codeforces/Way Too Long Words/index.cpp

@ -1,7 +1,6 @@
using namespace std;
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int n;

2
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

33
usaco/Breed Counting/index.cpp

@ -0,0 +1,33 @@
#include <cstdio>
#include <iostream>
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;
}
}

68
usaco/Mixing Milk/index.cpp

@ -0,0 +1,68 @@
#include <iostream>
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;
}

3
usaco/Mixing Milk/mixmilk.in

@ -0,0 +1,3 @@
10 3
11 4
12 5

3
usaco/Mixing Milk/mixmilk.out

@ -0,0 +1,3 @@
0
10
2

40
usaco/Shell Game/index.cpp

@ -0,0 +1,40 @@
#include <cstdio>
#include <iostream>
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;
}

0
usaco/Shell Game/shell.out

11
usaco/Teleportation/index.cpp

@ -1,15 +1,16 @@
#include <iostream>
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;
}

Loading…
Cancel
Save