2022年2月15日 星期二

994, rotting oranges

====
994, rotting oranges
====
BFS,
Shortest path,
Path existed
====
1. 給予一個箱子
'0'代表空
'1'代表好的
'2'代表爛的橘子

每分鐘爛的會向四個方向腐爛
求最大(久)箱子內還有好的

2. 起點是爛的->爛的(2) 座標/pair加入queue
隨後加入找好的(1)
但是要把它變爛(2)才 座標/pair加入queue

3. 多一個int fresh紀錄剩餘的好的
每次BFS加入記得扣掉

多一個int res紀錄第幾輪
return res
//剛開始的BFS還沒開始感染
//所以放在while裡面即可

4. 四個方向化成一個vector
vec<int> for={-1, 0, 1, 0, -1}
//只要1234, 2345 pair就好

====
class Solution{
public:
int orangesRotten( vec<vec<int>>& grid ){
  int m= grid.size(), n= grid[0].size()
  int fresh=0
  queue< pair<int,int>> q

  for i-m
    for j-n
      if grid[i][j] == 2
        q.push(<i-1,j>), q.push(<i+1,j>), q.push(<i,j-1>), q.push(<i,j+1>);
      if grid[i][j] == 1
        fresh++

  vec<vec<bool>> visited(m, vec<bool>(n, flase))
  int res=-1
  while( !q.empty() ){
    int qSize= q.size()
    while(qSize--){
      auto fq= q.front()
      q.pop()

      int x= fq.first
      int y= fq.second
      if(x>=0 && y>=0 && x<m && y<n && !visited[x][y] && grid[x][y]==1){
        visited[x][y]=true
        grid[x][y]=2
        q.push(<x-1,y>), q.push(<x+1,y>), q.push(<x,y-1>), q.push(<x,y+1>);
      }//if

    }//q.size
    res++
  }//q.empty

if(res==-1) return 0
if(fresh>0) return -1 //有橘子永遠不爛 莫急
}
};


2022年2月14日 星期一

問題類似的模式 奇摩子缺差很多

碰到難解的問題
尋求幫忙&討論
這是求助高手

看到關鍵字
一直下放問題要求解答&實驗
這是owner/打雜工

====
先不論做事這端人數多寡
類似的模式
奇摩子缺差很多

但卻取決於對方端怎麼處理

2022年2月6日 星期日

奧林帕斯十二神

奧林帕斯十二神
====
宙斯, Ζεύς/ Zeus
天空 雷霆之神
霹靂, 鷹, 橡樹, 節杖, 天平

希拉,  Ἥρα/ Hera
婚姻 家庭女神
孔雀, 石榴, 冠冕, 杜鵑, 獅子, 犢牛

波塞頓, Ποσειδών/ Poseidon
海洋 地震 海嘯之神
馬, 公牛, 海豚, 三叉戟

狄蜜特, Δημήτηρ/ Demeter
生育 農業 自然 季節女神
罌粟, 小麥, 火炬, 豬

雅典娜, Αθηνά/ Athena
智慧 技藝 戰爭 戰略女神
貓頭鷹, 後蛇, 橄欖樹

阿波羅, Απόλλων/ Apollō
太陽 光明 藝術之神
太陽, 豎琴, 弓箭, 烏鴉, 海豚, 天鵝, 狼, 鼠

阿蒂蜜絲, Ἄρτεμις/ Artemis
狩獵 孕育 月亮女神
月亮, 犢鹿, 獵犬, 犢熊, 蛇, 柏樹, 弓箭

阿瑞斯, Ἀρης/ Ares
戰爭 暴力 血腥之神
野豬, 蛇, 狗, 禿鷹, 矛盾

阿芙羅黛蒂, Αφροδίτη/ Aphrodite
愛 美 慾望女神
鴿子, 鳥, 蘋果, 蜜蜂, 天鵝, 番石榴, 玫瑰

赫菲斯托斯, Ἡφαιστος/ Hephaestus
工匠 火 鍛造之神
火, 砧, 斧頭, 驢, 錘子, 火鉗, 鵪鶉

荷米斯, ʽἙρμῆς/ Hermes
傳令神 冥界引導者
旅行 竊盜 體育 道路交叉邊界 商業之神
手杖, 翼鞋, 翼盔, 鶴, 龜

赫斯提亞, Εστία/ Hestia
火炬 家務 家庭女神
火炬

戴歐尼修斯, Διόνυσος/Dionysos
酒 慶典 狂歡之神
葡萄, 常春藤, 酒杯, 虎, 豹, 海豚, 山羊

2022年2月4日 星期五

Yeah. I don't speak virgin either.

- When a woman puts on an engagement ring, is like when Bilbo Baggins wears the One Ring in The Hobbit.

- Okay, can you say that again but not in nerd?

- Sure. The ring is like the cloak that Harry Potter wears to sneak around Hogwarts.

- Yeah. I don't speak virgin either.

<How I Met Your Mother, s08ep14, Ring Up>

You're gonna get endless requests to play some game that has something to do with gangsters and farming.

Robin: It's like the 15-time my dad has sent me a friend request. I'm just gonna hit 'accept'

Marshall: You don't want to see what's behind that door.
Robin: What are you talking about?

Ted: He's talking about my mom's 2000-word review of 'Fifth Shades of Grey'.
And 14 of those words were "vulva".

Marshall: You're gonna get endless requests to play some game that has something to do with gangsters and farming.

<How I Met Your Mother, s08ep13, Band or DJ?>

1162, As far from land as possible

====
1162, As far from land as possible
====
BFS,
Shortest path
Path existed
====
1. 目標是water, '0'
能有與
起點land, '1'能有的最長距離

2. 
定義一個queue<pair<int,int>>存放座標
BFS第一輪找的是起點->從'1'開始上下左右加第一輪BFS

3. 當queue不為空
front && pop座標
如果符合條件 //!visited && 是目標'0'
=>
visited true/ update cost/ 加入上下左右BFS

4. 當最遠的座標找到 會結束
=>
最遠的座標 在上一輪會將上下左右加入queue
=>
新的一輪 for step++
=>
都不符合條件 pop
一直都沒有符合條件的座標 所以都沒有加入queue
=>
while queue空了 跳出
=>
這次的step無作用
step-1才是預期

====
class Solution{

public:
int maxDistance( vec<vec<int>>& matrix ){
  int m= matrix.size(), n= matrix[0].size()
  vec<vec<bool>> visited= (m, vec<bool>(n, false))
  queue<pair<int,int>> pq
  for i-m
    for j-n
      if matrix(i,j) == 1
        pq.push(i-1,j)
        pq.push(i+1,j)
        pq.push(i,j-1)
        pq.push(i,j+1)

  int step=0
  while(!pq.empty()){
    step++
    int size=pq.size()
    for t-size{
    int x= pq.front().first
    int y= pq.front().second
    pq.pop()
    if( x>=0 && y>=0 && x<m && y<n && matrix(x,y)==0 && !visited(x,y) ){
      visited(x,y) = true
      pq.push(x-1,y)
      pq.push(x+1,y)
      pq.push(x,y-1)
      pq.push(x,y+1)
    }//if
    }//for
  }//while

  return step==1? -1: step-1
}
};

2022年2月3日 星期四

Oh, let's just bone a bunch so I'm another year older and still single?

Woman over 30 don't joke when it comes to commitment.

No 32-year-old woman is happy taking thing slow.
Trust me, Victoria has got friends from high school posting pictures of second babies on Facebook.

And you think your girlfriend all like, "Oh, let's just bone a bunch so I'm another year older and still single"?
Bitch, please.

<How I Met Your Mother, s08ep5, The Autumn of Break-Ups>