Try   HackMD

資訊之芽 Week4 作業題解

大十字

Link

講解

我們可以紀錄每一個人的

x 座標和
y
座標,
之後用兩個迴圈分別檢查直行橫列的座位,
找到其中的最大值。
要注意的是自己那一個座位的答案不能算。

Pseudo Code

let arr[][] denote the seat let X[] denote the X-coordinate let Y[] denote the Y-coordinate c := 0 ans := 0 int main() { input and record X[] and Y[]. input c for (i = 0 ~ n) if (arr[i][Y[c]] != c) ans = max(ans, arr[i][Y[c]]) for (j = 0 ~ m) if (arr[X[c]][j] != c) ans = max(ans, arr[X[c]][j]) output ans }

娃娃魚的站位哲學

Link

講解

題目在問

(x,y) 能不能距離 baba 陣列中其中一個點的距離小於等於
10
、距離 mie 陣列其中一個點的距離小於等於
10
、miao 陣列其中一個點的距離小於等於
12

所以就照著題意下去做就好了。

Pseudo Code

double distance(x1, y1, x2, y2) { return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) } bool isValid(a, b, c, baba[], mie[], miao[], x, y) { aa := 0 bb := 0 cc := 0 for each (x_i, y_i) in baba: if distance(x, y, x_i, y_i) <= 10: aa := 1 for each (x_i, y_i) in mie: if distance(x, y, x_i, y_i) <= 10: bb := 1 for each (x_i, y_i) in miao: if distance(x, y, x_i, y_i) <= 12: cc := 1 return aa && bb && cc }