Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add editorial + cpp code to angry cows #4176

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
pre-commit-ci[bot] committed Jan 5, 2024
commit 85651f9a5b2e4ac02a6ce9e622bcb16da5377035
37 changes: 15 additions & 22 deletions solutions/gold/usaco-597.mdx
Original file line number Diff line number Diff line change
@@ -81,42 +81,33 @@ int main() {
* @param r current radius at our position
* @param dir whether we're checking positions to the right/left
*/
function<bool(int, int, int, bool)> push = [&](int pos, int idx, int r, bool dir) {
function<bool(int, int, int, bool)> push = [&](int pos, int idx, int r,
ryanchou-dev marked this conversation as resolved.
Show resolved Hide resolved
bool dir) {
// finished search
if (idx >= n - 1 && dir == 0) {
return (idx >= n || pos + r >= bales[idx]);
}
if (idx <= 0 && dir == 1) {
return (idx < 0 || pos - r <= bales[idx]);
}
if (idx <= 0 && dir == 1) { return (idx < 0 || pos - r <= bales[idx]); }

if (dir == 0) { // go right
if (pos + r >= bales.back())
return true;
if (dir == 0) { // go right
if (pos + r >= bales.back()) return true;

int new_idx = idx;
while (new_idx < n && pos + r >= bales[new_idx]) {
new_idx++;
}
while (new_idx < n && pos + r >= bales[new_idx]) { new_idx++; }

// no progression
if (new_idx == idx)
return false;
if (new_idx == idx) return false;

return push(bales[new_idx - 1], new_idx, r - 2, dir);

} else { // go left
if (pos - r <= bales[0])
return true;
} else { // go left
if (pos - r <= bales[0]) return true;

int new_idx = idx;
while (new_idx < n && pos - r <= bales[new_idx]) {
new_idx--;
}
while (new_idx < n && pos - r <= bales[new_idx]) { new_idx--; }

// no progression
if (new_idx == idx)
return false;
if (new_idx == idx) return false;

return push(bales[new_idx + 1], new_idx, r - 2, dir);
}
@@ -140,7 +131,8 @@ int main() {
int pos = pos_lo + (pos_hi - pos_lo + 1) / 2;

// get index of first haybale to our right
int close = lower_bound(bales.begin(), bales.end(), pos) - bales.begin();
int close =
lower_bound(bales.begin(), bales.end(), pos) - bales.begin();

// is it possible to complete our explosions heading left?
if (close < n && push(pos, close, power, 1)) {
@@ -150,7 +142,8 @@ int main() {
}
}

int close = upper_bound(bales.begin(), bales.end(), pos_lo) - bales.begin();
int close =
upper_bound(bales.begin(), bales.end(), pos_lo) - bales.begin();
// is it possible to complete our explosions heading right?
if (push(pos_lo, close, power, 0)) {
hi = power;