forked from abheekd/usaco-practice
Abheek Dhawan
3 years ago
15 changed files with 165 additions and 17 deletions
@ -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. |
@ -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; |
|||
} |
|||
} |
@ -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; |
|||
} |
@ -0,0 +1,3 @@ |
|||
10 3 |
|||
11 4 |
|||
12 5 |
@ -0,0 +1,3 @@ |
|||
0 |
|||
10 |
|||
2 |
@ -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; |
|||
} |
Loading…
Reference in new issue