2022年2月28日 星期一

Because Love is the best thing we do.

It was a twisting, turning road that led to the end of the aisle,
and not everything along the way was perfect.

To be honest,
not everything to follow would be perfect either.
But what is?

Here is the secret, kids:
None of us can vow to be perfect.

In the end, all we could do is promise to love each other with everything we've got.

Because Love is the best thing we do.

<How I Met Your Mother, s09ep22, The End of the Aisle>

2022年2月27日 星期日

You will be shocked kids, when you discover how easy it is in life to part ways with people forever.

And that's how it go, kids.
The friends, neighbors, drinking buddies
and partners in crime you love so much when you're young,

as the years go by, you just lose touch.

====
You will be shocked kids,
when you discover how easy it is in life to part ways with people forever.

That's why, when you find someone you want to keep around, you do something about it.

<How I Met Your Mother, s9ep21, Gary Blauman>

Rally

Kids, no matter how hard it try,
even the best of us go a little too wild sometimes.

And in those moments, we all need someone who loves us to help us rally.

Even if that means lying once in a while.

<How I Met Your Mother, s09ep18, Rally>

Even when people roll their eye or call you crazy. Even then. Especially then!

If you're looking for the word that means caring about someone
beyond all rationality and wanting them to have everything they want,
no matter how much it destroy you, it's love.

And when you love someone, you just, you don't stop, ever.

Even when people roll their eye or call you crazy. Even then. Especially then!

You don't give up. Because if I could give up...
if I could just take the whole world's advice
and move on and find someone else, that wouldn't be love.

That would be... some other disposable thing that is not worth fighting for.

<How I Met Your Mother, s09ep17, Sumrise>

It's like the first lottery ticket I ever bought was, kaboom, jackpot, and I'm pretty sure I'm not going to win again

Tracy: I'm on permanent hiatus in the love department.
I guess I'm old-fashioned.
I believe that each of us only gets one. And I got mine already.

I was in love with somebody a long time ago,
and he died.

It's like the first lottery ticket I ever bought was,
kaboom, jackpot, and I'm pretty sure I'm not going to win again.

<How I Met Your Mother, s09ep16, How Your Mother Met Me>

A simple "yes" would've sufficed

Barney: You guys can't still see where Marshall slapped me, can you?

Ted: Your face looks like a "don't walk" signal.

Robin: Your face looks like a photo negative of the Hamburger Helper box.

Ted: A palm reader could tell Marshall's future by studying your face.

Robin: The phrase "talk to the hand cause the face ain't listening", doesn't work for you
cause the hand is on your face.

Barney: ...A simple "yes" would've sufficed.

<How I Met Your Mother, s09ep15, Unpause>

2022年2月24日 星期四

YOU'RE GOD DAMN RIGHT I DID!

- You want answers?

- I want the TRUTH!
- YOU CAN'T HANDLE THE TRUTH!

- Son, we live in a world that has walls,
and those walls have to be guarded by men with guns.

Who's gonna do it? You?
You, Lt. Weinberg?
I have a greater responsibility than you could possibly fathom.

You weep for Santiago and you curse the Marines. You have that luxury.
You have the luxury of NOT knowing what I know.

That Santiago's death, while tragic,
probably saved lives.
And my existence, while grotesque and incomprehensible to you, "saves lives".

You don't want the truth
because deep down in places you don't talk about at parties,
you want me on that wall.
You need me on that wall.

We use words like honor, code, loyalty.
We use these words as the backbone of a life spent defending something.
You use them as a punchline.

I have neither the time nor the inclination to explain myself to a man
who rises and sleeps under the blanket of the very freedom that I provide,
and then questions the manner
in which I provide it!

I would rather you just said "thank you"
and went on your way,
Otherwise, I suggest you pick up a weapon and stand a post.
Either way, I don't give a DAMN what you think you are entitled to!

- Did you order the code red?
- I did the job I...

- Did you order the Code Red?
- YOU'RE GOD DAMN RIGHT I DID!

<A Few Good Man, 1992>

2022年2月21日 星期一

Great. Then every decision you make from here on out, should be in service of that.

- Let me save you a few years.
Even if it sounds completely crazy..
What is it you want to do with your life?

- I want to end poverty.
- Great.
Then every decision you make from here on out, should be in service of that.

<How I Met Your Mother, s09ep16, How Your Mother Met Me>

2022年2月15日 星期二

207, Course schedule

207, Course schedule
====
Topological sort
Coloring

====
1. 給予一個n node number
一個vec<pair<int,int>>prerequest規則

2. prerequest表明<i,j>(有向圖)
如果要access i, 必須先有j
如果規則互斥(產生cycle) 則false

可能有很多方式
可用DFS 可用BFS 可用coloring

3. Coloring比較單純
生成一個map<int, vec<int>> adj來填入規則 //hashMap
->
adj[1].push_back(0)

生成一個vec<int> visited(n,0)來紀錄
如果走的過程中有碰到任何已經拜訪過的
則有cycle, false

否則true

====
class Solution{
public:
bool isCycle(vec<int>visited, vec<vec<int>>adj, int id){

  if visited[id] == 1 return true
  if visited[id] == 0{
    visited[id]=1
    for auto edge:adj[id]
    if isCycle(visited, adj, edge) return true
  }
  visited[id]=2 //?
  return false
}


bool canFinished(int n, vec<vec<int>>& pre){
  map<int, vec<int>> adj
  for auto edge: pre
    adj[edge[1]].push_back(edge[0])

  vec<int> visited(n, 0)
  for auto prule: adj{
    if(isCycle(visited, adj, prule.first)) return false
  }//
return true
}

};

1091, Shortest path in binary matrix

1091, Shortest path in binary matrix
====
BFS,
Shortest path,
Path existed

====
1. 題目給予vec<vec<int>>matrix
從左上 欲走到右下
路徑上只能是0 可以走八個方向

2. 一個queue< pair<int,int>>做BFS
一個vec<vec<bool>> visited記錄走過

3. 起點是左上
找它的鄰近加入queue

紀錄每次queue.size

而後每次找鄰近 且 matrix[][]==0 加入queue

4. 每次round++
當有座標碰到右下
return round(左上)

====
class Solution {
public:
int shortestPathBinaryMatrix(.vec<vec<int>>& grid ){

  int m= grid.size(), n= grid[0].size()
  if( grid[0][0]!=0 || grid[m-1][n-1]!=0 ) return -1

  queue< pair<int,int>> pq
  pq.push({1,0}), pq.push({0,1}), pq.push({1,1})

  vec<vec<bool>> visited=(m, vec<bool>(n, false))
  int res=1 //第一輪
  while(!pq.empty()){
    int qSize= pq.size()
    for(int t-qSize){
      auto qFront= pq.front()
      pq.pop()
      int x= qFront.first
      int y= qFront.second
      
      if(x==m-1 && y==n-1) return res+1 //第n輪加上右下+1

      if(x>=0 && y>=0 && x<m && y<n && !visited[x][y] && grid[x][y]==0){
        visited[x][y]=true
        pq.push({x-1,y-1}), pq.push({x-1,y}), pq.push({x-1,y+1})

        pq.push({x,y-1}), pq.push({x,y+1})

        pq.push({x+1,y-1}), pq.push({x+1,y}), pq.push({x+1,y+1})
      }//if
    }//for qSize
    res++

  }//while q.empty
  return -1
}
};

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>

542, 01_matrix

====
542, 01_matrix
====
BFS,
Shortest path
Path existed
====
1. 題目希望將給予的matrix
化成
每個單元離它最近的'0'的距離

2. BFS用的是queue, 因為用了座標
所以用queue< pair<int,int> >來紀錄加入queue的座標

3. 從(0,0)開始做BFS
當queue不為空的時候
-> pop單元
-> 針對pop的動作處理BFS //加入新的單元
//新增step or cost

4. Visited是必須的
產生一個vec<vec<bool>>visited來紀錄已經處理過的單元
以免單元間產生無窮迴圈
->
當沒有visited
符合題目條件
則處理
BFS //push

====
class Solution{

public:
vec<vec<int>> updateMatrix( vec<vec<int>>&matrix ){
  int m= matrix.size()
  int n= matrix[0].size()
  queue<pair<int,int>> pq

  for i-m
    for j-n
      if(matrix(i,j) == 0){
      //先從'0'開始 因為第一次與零的距離是“0”
      //之後逐漸加一
        pq.push({i-1, j});
        pq.push({i+1, j});
        pq.push({i, j-1});
        pq.push({i,j-1});
        //上下左右加入queue //所有第一層的node
      }

  int step=0
  vec<vec<bool>> visited(m, vec<bool>(n, false) )
  while( !pq.empty() ){
  step++
  int size= pq.size() //紀錄當前的queue size來控制當次需要做多少次
  for(i=0; i<size; i++){
    auto Front= pq.front()
    int x=Front.first
    int y=Front.second
    pq.pop()

    if(x>=0&& y>=0&& x<m&& y<n&& !visited(x,y)&& matrix(x,y)==1){
      //開始找‘1’,因為開始要填1到0的距離
      visited(x,y)=true
      matrix(x,y)=step
      //因為拜訪過了 且當前的距離已經填入
      pq.push({x-1, j});
      pq.push({x+1, j});
      pq.push({i, y-1});
      pq.push({i,y-1});
      //第n次層的上下左右 加入queue

    }//if
  }//for
  }//while

}
};

2022年2月2日 星期三

Then it's baby's turn to be crazy.

- She's pregnant.
She gets to be crazy. You have to be the sane one.

- So what, I don't get to be crazy again til the baby comes?

- No. Then it's baby's turn to be crazy.

- Then when do I get to be crazy again?

- Never.

<How I Met Your Mother, s07ep21, Now We're Even>

Every time I go out and have an awesome night and you're not there, that's another hundred points in my column

I'm talking about the game of life, Ted.
Scoreboard. Better wardrobe: 75 points.
Apartment on a higher floor: 90 points.
Longer name: 110 points.

Every time I go out and have an awesome night and you're not there,
that's another hundred points in my column.

So, yeah, I'm in the lead.
<How I Met Your Mother, s07ep21, Now We're Even>

2022年2月1日 星期二

Top10 things Marshall said on his wedding night

Marshall: It's hard for the little guy to perform under pressure.
Barney: "Top10 things Marshall said on his wedding night."

Kevin: Whoa! It was small, but I think I felt something.
Robin: "Top10 things Lily said on her wedding night."

Marshall: Stop laughing at it, Lily.
(All): Top10 things Marshall said on his wedding night!!

<How I Met Your Mother, s07ep16, The Drunk Train>

Oh, God. This is parenthood, isn't it?

Every 30 seconds, there's another crisis that needs to be dealt with, and I have to deal with it.
This is..

Oh, God. This is parenthood, isn't it?
<How I Met Your Mother s07ep15, The Burning Beekeeper>

802, Find eventual safe states

====
802, Find eventual safe states
====
DFS,
cycle find

有向/無向圖找cycle不一樣
有向需要三個顏色(還沒看過/ 還在看/ 已經看完
無向需要兩個顏色(visited/ un-visited

過程中有碰到訪問過/看過的node
就是有cycle

====
a)
1. 題目給予一個graph
定義一個int dp(n, 0)初值

0, 還沒看過
-1,還在看
1,已經看完

2. DFS一進去
先將dp[i]=-1 //還在看
然後針對graph[i][]一一DFS檢查
如果有false則return false

3. 如果graph[i][]跑完 都沒看到cycle 
//如果沒有看到dp==-1, i.e還在看

則dp[i]=1, i.e已經看完
return true
else
return dp[i]==1

4. main一個for跑DFS
如果false,就不加入結果
否則是安全的,加入

====
class Solution{

public:
bool DFS( vec<vec<int>>&graph, vec<int>&dp, int i){
  if ( dp[i] ) //-1 ->false, 1 ->true
    return dp[i]==1

  dp[i]=-1
  for auto t:graph[i].begin; t!=graph[i].end; t++
    if ( !DFS( graph, dp, *t ) )
      return false

  dp[i]=1
  return true;
}
vec<int> eventualSafe( vec<vec<int>>&graph ){
  int n=graph.size()
  vec<int> res
  vec<int> dp(n, 0)
  for i-n
    if( DFS( graph, dp, i )
      res.push_back(i)

  return res
}
}

733, Flood Fill

====
733, Flood Fill
====
DFS,
from each un-visited node/island problems

====
1. 題目給予一個vec<vec<int>>M
一個起始的座標
以及變更的新數值

2. 定義一個vec<vec<bool>>visited
DFS( M, visited, i, j, m, n, new )走過上下左右的同值/同於起始 的所有node

====
class Solution{

void DFS( vec<vec<int>>& matrix, vec<vec<bool>>&visited, int i, int j, int m, int n, int old, int new){
  if( i<0 || j<0 || i>=m || j>=n || matrix(i,j)!=old || visited(i,j) ) return;

  visited(i,j)= true;
  matrix(i,j)= new;
  DFS( matrix, visited, i-1, j, m, n, matrix(i,j), new)
  DFS i+1
  DFS j-1
  DFS j+1

}

vec<vec<int>> FloodFill( vec<vec<int>>& matrix, int x, int y, int newColor ){
  int m= matirx.size(), n= matrix[0].size()
  vec<vec<bool>> visited= (m, false)

  if matrix(x,y)!=newColor
    DFS( matrix, visited, x, y, matrix(x,y), newColor)

  return matrix
}