原创 Catenyms poj hoj 歐拉回路輸出路徑

#include <stdio.h> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn=1001

原创 487-3279 hoj 模擬AC

/*之前寫的在poj1002上AC了,但是在HOJ上過不了,現在又寫了一遍,在HOJ 上過了。 一個是字符串排序的寫法,可以當模板用。 其餘都是細節問題。*/ #include <stdio.h> #include <cstring>

原创 一類計算問題小結poj&hoj Set Definition ,Humble Numbers ,Ugly Numbers 因子構造法

/*這類問題都是給一些只能由某些特定因子乘積組成的數,然後求第n個數的大小。 做法就是每次用所給的條件來構造因子,預處理出前N項的值,複雜度O(N),查詢複雜度O(1).*/ Set Definition.code #include <

原创 多重揹包的二進制優化 悼念512汶川大地震遇難同胞――珍惜現在,感恩生活

/*今天剛看了揹包九講的多重揹包優化,經典啊! 將n[i]件等值的物品用二進制轉化爲log(n)件物品,這個是個很大的優化, 具體的處理是對每一件物品的費用和價值也都乘上相應的二進制係數。*/ #include <stdio.h> #i

原创 POJ Stars 2352

#include <stdio.h> #include <cstring> int c[32001]; int s[15001]; inline int lowbit(int x) { return x&(-x); } void

原创 線段樹+DP 求區間連續最大子段和 hoj Candy

/* f爲從左端開始的最大子段和,b爲從右端開始的最大子段和。 pushup中的爲最大字段和的狀態轉移方程。*/#include <stdio.h> #include <cstring> #define maxn 100001 #in

原创 POJ 2029 Get Many Persimmon Trees

#include <stdio.h> #include <cstring> const int maxn=101; int c[maxn][maxn]; inline int lowbit(int x) { return x&(-

原创 Go hdu 4158 hoj 簡單搜索

/*搜索中狀態加入隊列時就要立即更新標誌, 不能出隊的時候更新,否則中間有部分狀態會重複搜索造成錯誤。*/ #include <stdio.h> #include <cstring> #include <queue> #include <

原创 POJ 2481 Cows

#include <stdio.h> #include <cstring> #include <algorithm> using namespace std; const int maxn=100005; int c[maxn+1]; s

原创 Count Color 線段樹成段更新 hoj &poj

/*注意在查詢的時候要將標記下方。*/ #include <stdio.h> #include <cstring> #define maxn 100001 int c[maxn<<2]; bool color[31]; int laz

原创 Guardian of Decency hoj poj 二分圖匹配 不錯的題

/*這個題的原意是求不能成爲夫婦的人的最大數量。 但是這個只需要滿足四個條件中的一個就可以連一條邊,這樣匹配後產生的課匹配的邊數量過多, 就超時了。 可以反過來想,求不滿足題意,即能成爲夫婦的點數,再用總數n-此時的最大匹配數m。 因爲

原创 HOJ 2686 Magic-Box

#include <stdio.h> #include <cstring> const int maxn=202; int c[maxn][maxn][maxn]; inline int lowbit(int x) { retur

原创 Ultra-QuickSort

#include <stdio.h> #include <cstring> #include <algorithm> #include <iostream> using namespace std; const int maxn=5000

原创 簡單計算求組合數 Binomial Showdown

#include <stdio.h> int main() { double n,k; while(scanf("%lf%lf",&n,&k)==2) { if(n==0&&k==0) break;

原创 POJ 1195 Mobile phones

#include <stdio.h> #include <cstring> const int maxn=1050; int c[maxn][maxn]; inline int lowbit(int x) { return x&(