通常用來detect loop,判斷從哪段開始有loop
解法可以想像是龜兔賽跑,兔子兩倍速,烏龜一倍速前進
假設c是起點距離loop的距離,k是起點距離第一次相遇點的距離,loop 長度是L
angledark0123 發表在 痞客邦 留言(0) 人氣(153)
在研究為什麼 List<List<Integer>> res = new ArrayList<>();
為什麼可以這樣初始,然後研究到這個
angledark0123 發表在 痞客邦 留言(0) 人氣(90)
同樣是看code學習,把同班同學好的code拿出來看,不懂的筆記在這裡
1. 如何有效率free vector memory
因為用clear() 本身只是把element 清掉,但是空間並不會減少,有人主張用resize,不過更好的是用 temporary vector swap
angledark0123 發表在 痞客邦 留言(0) 人氣(59)
hw1 Sorting:
input.txt
----------------------
N: number of sequence
SEQ1
SEQ2
output.txt
----------------------
sorted SEQ1
sorted SEQ2
Example.
input.txt
----------------------
2
8 5 9
2 1
output.txt
----------------------
5 8 9
1 2
angledark0123 發表在 痞客邦 留言(0) 人氣(4)
Normally you will have to explicitly declare your own destructor if:
1.You are declaring a class which is supposed to serve as a base for inheritance involving polymorphism, if you do you'll need a virtual destructor to make sure that the destructor of a Derived class is called upon destroying it through a pointer/reference to Base.
angledark0123 發表在 痞客邦 留言(0) 人氣(6)
來記錄一下這次搞了我一點時間的message pack
http://msgpack.org
簡單來說就是一個更簡易binary pack 數據的方式,會依照data type,來決定怎麼包
angledark0123 發表在 痞客邦 留言(0) 人氣(64)
這似乎也是很多人會遇到的問題,就是使用feof最後一行有時候會出現多讀一次的狀況
但其實問題是這樣,在最後一行後才是eof,在 C 的函式下, 只有當上一個讀取已經產生 end of file 錯誤的時候, feof() 才會傳回 true
所以在最後一行讀取後,feof 並不成立,然後直到一次read fai,eof才會被讀到 ,造成多while 一次
angledark0123 發表在 痞客邦 留言(0) 人氣(3,259)
這次作業memory 讀取使用紀錄時,因為只要用部分資料,所以查了一下用法
發現原來fscanf 可以選擇要讀什麼跳過什麼
這是寫比較詳細的網站,不過他用的是scanf 不過大同小異啦,只是看用什麼輸入
angledark0123 發表在 痞客邦 留言(0) 人氣(5,658)
這是之前作業在做quick sort的時候用到的,發現這種寫法很有趣
原來2d可以用這種array的array的方式做出來
以下出自:http://blog.xuite.net/ylps50138/web/31772356-C%2B%2B+%E7%9A%84%E5%8B%95%E6%85%8B%E9%85%8D%E7%BD%AE%E9%99%A3%E5%88%97+----+%E4%BB%A5%E4%BA%8C%E7%B6%AD%E9%99%A3%E5%88%97%E7%82%BA%E4%BE%8B
angledark0123 發表在 痞客邦 留言(0) 人氣(3,573)
有用到一些覺得有趣的指令所以來記錄一下
ipcs -m 可以看 ipc memory的部分
ipcrm -m shmid 指定砍掉shmid
angledark0123 發表在 痞客邦 留言(0) 人氣(20)