原创 hdu 1535 spfa

建個正向的圖。 建個反向的圖。 2遍spfa搞定。 #include<cstdio> #include<iostream> #include<cstring> #include<queue> #include<algorithm> us

原创 zoj2968 Difference Game

分析: 一   首先答案可以是正數。       那就簡單了,先把所有的數進行升序排列,因爲ga數組最小的數一定比gb數組最大的數大。所以排列後一定會在相連的位置得到答案。所以就從左到右便利分割點。 左邊作爲ga數組,右邊作爲gb數組,然

原创 hdu 1806線段樹 區間合併

#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; int num[100005]; const i

原创 C++ cin cout

未完待續。。。。。 cin是以空格作爲分隔的。 cin是不能讀取回車的,要用cin.get()讀取

原创 zoj 3705 Applications

模擬題。去年省賽第一道。 #include<cstdio> #include<iostream> #include<algorithm> #include<map> #include<cmath> #include<cstring> u

原创 最長公共子序列

所有的公共最長上升序列有三種解法: (1)枚舉法 (2)遞歸 (3)動態規劃 枚舉法: 就是枚舉較短串中的所有子串z^n,然後直接進行字符串匹配。總之,慢死你。 遞歸,動態規劃都是一樣的方程 如果要輸出路徑,那很明顯是在對角線移動的

原创 伸展樹(Splay tree)淺談

樹看的越來越多,越來越神奇。 看伸展樹這種神級數據結構之前,建議大家首先徹底明白二叉搜索樹,這是萬樹的基礎。 然後可以去看下treap,最好再去看下紅黑樹。如果有線段樹的基礎那更好了,我們會發現線段樹難以實現一些直接刪除,直接插入的數據。

原创 C++ map基本操作

C++ map的基本操作和使用    來源:(http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html) - C++ map的基本操作和使用_Live_新浪博客     Map是c

原创 hdu4004 The Frog's Games 二分

直接貼代碼 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #incl

原创 pat 1025 反轉鏈表

注意到地址是一些數字,所以直接用int存了,這樣就可以不用map了。 機制的學叔。我就是個逗逼。 #include <stdio.h> int node[100000][3]; int list[100000]; int main()

原创 hdu 4302 STL multiset

用multiset過 #include<cstdio> #include<cstring> #include<iostream> #include<set> #include<cmath> using namespace std; i

原创 poj 2342 樹形DP

樹形DP入門題目。 樹形DP說白了就是在搜索的時候動態規劃。 只要你懂的深搜+動態規劃,就能理解這個基礎題了。 先直接搜索到最底層,然後一層一層動態規劃,可以說有點像數塔。 dp[i][1],dp[i][0]代表取這個節點和不取這個節點,

原创 poj 2352 線段樹

注意到題目中給的y是遞增的,那個y沒什麼用,直接線段樹維護一段1,x的區間。 #include<string> #include<iostream> #include<cstdio> #include<cstring> #include

原创 zoj 3327 Friend Number 模擬題

一年的省賽題目。 先容我罵一下,這題目有病吧,我調試了一個下午+晚上,好不容易纔順利A了,真是坑。 比賽中能做出來的那絕對是厲害啊!!。 我的思路,方法可能有笨: 1.首先判斷下有幾個0,有一個0的話,      一  。判斷0後面有沒

原创 hdu 1027 STL next_permutation

求下一個排列模板 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() {