Skip to content

1511 23 t1 buildfix #233

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

Merged
merged 7 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions data/course-revision/1511-22T3/shauns_sheep.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ desc: Determine if Shaun can drive to the end of the road!
class: COMP1511
difficulty: 3
---

# Shaun's Sheeps
Shaun Forza needs your help! Currently, Shaun is on the uppermost left $(1, 1)$, of a two lane road of $n$ length, specifically a $2 \times n$ rectangle grid, and needs to transport all his sheep to the end, $(2, n)$ safely. Shaun's car, the Sheepgatti Chiron, can only move in four directions, that is, left, right, up, and down.

Unfortunately, aliens have attacked Earth's sheep, and one notorious alien, Blamo, is specifically targeting Shaun by dropping sheep onto the road, causing certain positions in the grid to be blocked (forbidding Shaun to drive over them).
Shaun Forza needs your help! Currently, Shaun is on the uppermost left $(1, 1)$, of a two lane road of $n$ length, specifically a $2 \times n$ rectangle grid, and needs to transport all his sheep to the end, $(2, n)$ safely. Shaun's car, the Sheepgatti Chiron, can only move in four directions, that is, left, right, up, and down.

Unfortunately, aliens have attacked Earth's sheep, and one notorious alien, Blamo, is specifically targeting Shaun by dropping sheep onto the road, causing certain positions in the grid to be blocked (forbidding Shaun to drive over them).

Fortunately, Blamo is not a very smart alien, and if he happens upon a position where he previously dropped a sheep, Blamo, mistaking the sheep for Shaun, will blast the sheep into dust, freeing the position up again for Shaun.
Fortunately, Blamo is not a very smart alien, and if he happens upon a position where he previously dropped a sheep, Blamo, mistaking the sheep for Shaun, will blast the sheep into dust, freeing the position up again for Shaun.

Shaun knows that Blamo only has $p$ minutes, and it takes him exactly 1 minute to either drop a sheep or blow it up into smithereens, where the $i$-th minute is where Blamo chooses to target position $(r_{i}, c_{i})$.
Shaun knows that Blamo only has $p$ minutes, and it takes him exactly 1 minute to either drop a sheep or blow it up into smithereens, where the $i$-th minute is where Blamo chooses to target position (**r<sub>i</sub>**, **c<sub>i</sub>**).

Shaun wonders, after every minute, whether it is still possible for him to move from his starting position $(1, 1)$, to the end, $(2, n)$ without driving into any sheep.

Although Shaun is a superb driver, he isn't skilled enough to calculate such positions, and needs your help in writing a program, `shauns_sheep.c` to figure out if it is possible for him to drive to the end.

The first line of input contains the integers $n$ and $p$.
And each subsequent $p$ lines contain two integers $r_{i}$ and $c_{i}$.
And each subsequent $p$ lines contain two integers **r<sub>i</sub>** and **c<sub>i</sub>**.

Your output should consist of either a 'Yes' if Shaun can make it to the end, or 'No' if not, after every minute.

The output from your program should look **exactly** like this:

```bash
$ dcc shauns_sheep -o shauns_sheep
$ ./shauns_sheep
Expand All @@ -40,6 +43,7 @@ Yes
```

## Assumptions/Restrictions/Clarifications

$2 \leq n \leq 10^5$
$1 \leq p \leq 10^5$
Note that this means that your inputs will fit in an `int`.
Expand All @@ -53,7 +57,6 @@ When you think your program is working, you can use CSE autotest to test your so
$ 1511 csesoc-autotest shauns_sheep
```


## Solution

You can view the solution code to this problem [here](https://github.com/csesoc/comp1511-revision-t1-2022/blob/master/solutions/shauns_sheep/solution.c).
34 changes: 22 additions & 12 deletions data/course-revision/1511-22T3/sweet_potatoes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@ desc: Determine the best place to setup your Sweet Potato Stall!
class: COMP1511
difficulty: 2
---

# X marks the Starch
You've recently been reading the news and have seen a gap in the market for delicious, delectable sweet potatoes!

You've recently been reading the news and have seen a gap in the market for delicious, delectable sweet potatoes!
You've decided to set up shop at Town Hall, but unfortunately, you can only serve people in a cross pattern!

```
X 0 X
0 X 0
X 0 X
```
Even worse, your constant back pain forces you to stay still for the entire day.
Luckily, you've prepared for this and you have a map with $m$ rows and $n$ columns that contains the density of people who walk throughout Town Hall everyday.

Even worse, your constant back pain forces you to stay still for the entire day.
Luckily, you've prepared for this and you have a map with **m** rows and **n** columns that contains the density of people who walk throughout Town Hall everyday.
You know that everyone will want to taste your sweet potatoes as long as you can serve them. Therefore, your task is to write a program `sweet_potatoes.c` that finds the best place to put your cart so that you will end up serving the most people!

For each testcase, print three integers - the row and column index (starting from $0$) of the best position to place your cart, and the total number of people you will serve.
For each testcase, print three integers - the row and column index (starting from **0**) of the best position to place your cart, and the total number of people you will serve.

The first line contains integer $m, n$.
The next $m$ lines will have $n$ integers $r_{1}, r_{2}, ...,r_{n}$ denoting the density of people at that coordinate.
The first line contains integer **m, n**.
The next **m** lines will have **n** integers **r<sub>1</sub>, r<sub>2</sub>, ...,r<sub>n</sub>** denoting the density of people at that coordinate.

The output from your program should look **exactly** like this:

```bash
Input:
$ dcc sweet_potatoes.c -o sweet_potatoes
Expand All @@ -34,28 +39,33 @@ $ ./sweet_potatoes
```

### Assumptions/Restrictions/Clarifications
$3 \leq m, n \leq 10^5$
$0 \leq r_{i} \leq 10^5$ for any $1 \leq i \leq n$.
Note that this means your inputs will fit inside an `int`.

$3 \leq m, n \leq 10^5$
$0 \leq$ **r<sub>i</sub>** $\leq 10^5$ for any $1 \leq i \leq n$.
Note that this means your inputs will fit inside an `int`.

If there exists multiple places where it is best to place your cart, any applicable answer is accepted.

Note that you can place your cart at indexes where it is not possible to form an X shape.
Note that you can place your cart at indexes where it is not possible to form an X shape.
For example,

```
X 0 0
0 X 0
0 0 0
```

at the uppermost left corner of your map.

Hint: You can dynamically allocate an array by defining an array of int pointers in the form `int **arr`.
Hint: You can dynamically allocate an array by defining an array of int pointers in the form `int **arr`.
This can be thought as a pointer to a bunch of integer pointers, which can then be thought of as a sort of 2D array when dynamically allocated.

```
**int -> *int *int *int *int
| | | |
int int int int
```
```

## CSE Autotest

When you think your program is working, you can use CSE autotest to test your solution.
Expand Down