You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: data/course-revision/1511-22T3/shauns_sheep.mdx
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -4,25 +4,28 @@ desc: Determine if Shaun can drive to the end of the road!
4
4
class: COMP1511
5
5
difficulty: 3
6
6
---
7
+
7
8
# Shaun's Sheeps
8
-
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.
9
9
10
-
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).
10
+
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.
11
+
12
+
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).
11
13
12
-
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.
14
+
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.
13
15
14
-
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})$.
16
+
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>**).
15
17
16
18
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.
17
19
18
20
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.
19
21
20
22
The first line of input contains the integers $n$ and $p$.
21
-
And each subsequent $p$ lines contain two integers $r_{i}$ and $c_{i}$.
23
+
And each subsequent $p$ lines contain two integers **r<sub>i</sub>** and **c<sub>i</sub>**.
22
24
23
25
Your output should consist of either a 'Yes' if Shaun can make it to the end, or 'No' if not, after every minute.
24
26
25
27
The output from your program should look **exactly** like this:
28
+
26
29
```bash
27
30
$ dcc shauns_sheep -o shauns_sheep
28
31
$ ./shauns_sheep
@@ -40,6 +43,7 @@ Yes
40
43
```
41
44
42
45
## Assumptions/Restrictions/Clarifications
46
+
43
47
$2 \leq n \leq 10^5$
44
48
$1 \leq p \leq 10^5$
45
49
Note that this means that your inputs will fit in an `int`.
@@ -53,7 +57,6 @@ When you think your program is working, you can use CSE autotest to test your so
53
57
$ 1511 csesoc-autotest shauns_sheep
54
58
```
55
59
56
-
57
60
## Solution
58
61
59
62
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).
Copy file name to clipboardExpand all lines: data/course-revision/1511-22T3/sweet_potatoes.mdx
+22-12Lines changed: 22 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,29 @@ desc: Determine the best place to setup your Sweet Potato Stall!
4
4
class: COMP1511
5
5
difficulty: 2
6
6
---
7
+
7
8
# X marks the Starch
8
-
You've recently been reading the news and have seen a gap in the market for delicious, delectable sweet potatoes!
9
+
10
+
You've recently been reading the news and have seen a gap in the market for delicious, delectable sweet potatoes!
9
11
You've decided to set up shop at Town Hall, but unfortunately, you can only serve people in a cross pattern!
12
+
10
13
```
11
14
X 0 X
12
15
0 X 0
13
16
X 0 X
14
17
```
15
-
Even worse, your constant back pain forces you to stay still for the entire day.
16
-
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.
18
+
19
+
Even worse, your constant back pain forces you to stay still for the entire day.
20
+
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.
17
21
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!
18
22
19
-
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.
23
+
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.
20
24
21
-
The first line contains integer $m, n$.
22
-
The next $m$ lines will have $n$ integers $r_{1}, r_{2}, ...,r_{n}$ denoting the density of people at that coordinate.
25
+
The first line contains integer **m, n**.
26
+
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.
23
27
24
28
The output from your program should look **exactly** like this:
29
+
25
30
```bash
26
31
Input:
27
32
$ dcc sweet_potatoes.c -o sweet_potatoes
@@ -34,28 +39,33 @@ $ ./sweet_potatoes
34
39
```
35
40
36
41
### Assumptions/Restrictions/Clarifications
37
-
$3 \leq m, n \leq 10^5$
38
-
$0 \leq r_{i} \leq 10^5$ for any $1 \leq i \leq n$.
39
-
Note that this means your inputs will fit inside an `int`.
42
+
43
+
$3 \leq m, n \leq 10^5$
44
+
$0 \leq$ **r<sub>i</sub>** $\leq 10^5$ for any $1 \leq i \leq n$.
45
+
Note that this means your inputs will fit inside an `int`.
40
46
41
47
If there exists multiple places where it is best to place your cart, any applicable answer is accepted.
42
48
43
-
Note that you can place your cart at indexes where it is not possible to form an X shape.
49
+
Note that you can place your cart at indexes where it is not possible to form an X shape.
44
50
For example,
51
+
45
52
```
46
53
X 0 0
47
54
0 X 0
48
55
0 0 0
49
56
```
57
+
50
58
at the uppermost left corner of your map.
51
59
52
-
Hint: You can dynamically allocate an array by defining an array of int pointers in the form `int **arr`.
60
+
Hint: You can dynamically allocate an array by defining an array of int pointers in the form `int **arr`.
53
61
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.
62
+
54
63
```
55
64
**int -> *int *int *int *int
56
65
| | | |
57
66
int int int int
58
-
```
67
+
```
68
+
59
69
## CSE Autotest
60
70
61
71
When you think your program is working, you can use CSE autotest to test your solution.
0 commit comments