Skip to content

Commit 0dca687

Browse files
authored
23 t1 1511 problems (#231)
* Add files via upload * Update sweet_potatoes.mdx * Update sweet_potatoes.mdx * Update shauns_sheep.mdx * Update shauns_sheep.mdx
1 parent b81f091 commit 0dca687

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Shaun's Sheep
3+
desc: Determine if Shaun can drive to the end of the road!
4+
class: COMP1511
5+
difficulty: 3
6+
---
7+
# 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+
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).
11+
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.
13+
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})$.
15+
16+
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+
18+
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+
20+
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}$.
22+
23+
Your output should consist of either a 'Yes' if Shaun can make it to the end, or 'No' if not, after every minute.
24+
25+
The output from your program should look **exactly** like this:
26+
```bash
27+
$ dcc shauns_sheep -o shauns_sheep
28+
$ ./shauns_sheep
29+
5 5
30+
2 3
31+
1 4
32+
2 4
33+
2 3
34+
1 4
35+
Yes
36+
No
37+
No
38+
No
39+
Yes
40+
```
41+
42+
## Assumptions/Restrictions/Clarifications
43+
$2 \leq n \leq 10^5$
44+
$1 \leq p \leq 10^5$
45+
Note that this means that your inputs will fit in an `int`.
46+
It is guaranteed that $(1, 1)$ and $(2, n)$ will never be targeted.
47+
48+
## CSE Autotest
49+
50+
When you think your program is working, you can use CSE autotest to test your solution.
51+
52+
```bash:~/1511-revision/shauns_sheep
53+
$ 1511 csesoc-autotest shauns_sheep
54+
```
55+
56+
57+
## Solution
58+
59+
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).
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Sweet Potatoes
3+
desc: Determine the best place to setup your Sweet Potato Stall!
4+
class: COMP1511
5+
difficulty: 2
6+
---
7+
# 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+
You've decided to set up shop at Town Hall, but unfortunately, you can only serve people in a cross pattern!
10+
```
11+
X 0 X
12+
0 X 0
13+
X 0 X
14+
```
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.
17+
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+
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.
20+
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.
23+
24+
The output from your program should look **exactly** like this:
25+
```bash
26+
Input:
27+
$ dcc sweet_potatoes.c -o sweet_potatoes
28+
$ ./sweet_potatoes
29+
3 5
30+
15 23 33 81 15
31+
01 93 51 53 12
32+
08 38 24 12 53
33+
1 2 205
34+
```
35+
36+
### 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`.
40+
41+
If there exists multiple places where it is best to place your cart, any applicable answer is accepted.
42+
43+
Note that you can place your cart at indexes where it is not possible to form an X shape.
44+
For example,
45+
```
46+
X 0 0
47+
0 X 0
48+
0 0 0
49+
```
50+
at the uppermost left corner of your map.
51+
52+
Hint: You can dynamically allocate an array by defining an array of int pointers in the form `int **arr`.
53+
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.
54+
```
55+
**int -> *int *int *int *int
56+
| | | |
57+
int int int int
58+
```
59+
## CSE Autotest
60+
61+
When you think your program is working, you can use CSE autotest to test your solution.
62+
63+
```bash:~/1511-revision/sweet_potatoes
64+
$ 1511 csesoc-autotest sweet_potatoes
65+
```
66+
67+
## Solution
68+
69+
You can view the solution code to this problem [here](https://github.com/csesoc/comp1511-revision-t1-2022/blob/master/solutions/sweet_potatoes/solution.c).

0 commit comments

Comments
 (0)