原创 字節對齊學習筆記

首先要分清楚三個概念:自身對齊值、指定對齊值、有效對齊值。 自身對齊值:數據類型本身的對齊值,例如char類型的自身對齊值是1,short類型是2; 指定對齊值:編譯器或程序員指定的對齊值,32位單片機的指定對齊值默認是4; 有效對齊值:

原创 HDU 1000 A + B Problem

作爲經典的ACM入門題,這應該是很多人入坑時做的第一道題,可以說,A+B問題對ACMer的意義相當於Hello World對於程序員的意義。很多題目很簡單,但是有些人知道做法也不一定能AC,因此借這道題講講初學者可能遇到的種種問題。讓我

原创 TinyURL記錄

之前去網易遊戲面試,結果涼了。 當時面試官問了我一個問題:如何實現一個短網址(Tiny url)系統。當時我只說是建立一個映射,就跟哈希表的原理差不多。然後面試官問我用較短的網址去映射那麼多的較長的網址,短網址夠用嗎?我當時理所當然地覺得

原创 [LeetCode] Subtree of Another Tree

題目鏈接:點擊打開鏈接 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node va

原创 [LeetCode] Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins. For example, the follow

原创 根據先序遍歷數列和中序遍歷數列重建二叉樹

題目描述 輸入某二叉樹的前序遍歷和中序遍歷的結果,請重建出該二叉樹。假設輸入的前序遍歷和中序遍歷的結果中都不含重複的數字。例如輸入前序遍歷序列{1,2,4,7,3,5,6,8}和中序遍歷序列{4,7,2,1,5,3,8,6},則重建二

原创 [LeetCode] Poor Pigs

There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the s

原创 2016 GDCPC 賽後小感

昨天去中大參加了2016的廣東ACM省賽,結果並不令人滿意,只AC了五題,估計連銅牌也拿不到。雖然是發生了很多狀況,導致有兩道簡單的題目也沒有做,但是主要原因還是我們的個人實力不足。說實話,比賽完我們三個都挺沮喪的。這個成績,去到別的學校

原创 [LeetCode] Binary Watch

A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minut

原创 hdu4463 Outlets

這是一道最小生成樹模板題 #include<iostream> #include<cstring> #include<vector> #include<cmath> using namespace std; const int INF=

原创 Socket編程學習記錄

最近在鼓搗Ubuntu,開始正式學習Socket網絡編程。 今晚跟着教程做好了一個echo服務器,還挺有成就感的。 服務器端:echosrv.c #include <unistd.h> #include <sys/types.h> #i

原创 關於lowbit函數

lowbit(x)是x的二進制表達式中最低位的1所對應的值。 比如,6的二進制是110,所以lowbit(6)=2。 最近回頭看樹狀數組,發現關於lowbit()函數,目前有兩種算法。 第一種是比較常見的,也是我一直在用的: int