原创 poj2774 Long Long Message && hdu 1403 Longest Common Substring 最長公共字串【後綴數組(倍增)】

參考自2009年國家集訓隊論文《後綴數組——處理字符串的有力工具》(羅穗騫) 將串a與串b連接後用後綴數組求最大height #include<iostream> #include<cstring> using namespace st

原创 HDU 3560 Graph’s Cycle Component 【並查集】

並查集分組,deg必需爲2纔是circle #include<iostream> #include<cstdio> using namespace std; const int maxn=100000+10; int p[maxn],r[

原创 2012金華網絡賽賽後【缺ABC】

A Mines (HDU 4400) B Battery (HDU 4401) C Magic Board (HDU 4402) D A very hard Aoshu problem (HDU 4403) 枚舉“=”的

原创 usaco 1.4.2 Packing Rectangles

圖上描繪的就是所有的基本擺放方法 即4的全排列種方法+交換任意x,y=所有的擺放方法 /* ID: w.x.f.g1 PROG: packrec LANG: C++ */ #include<iostream> #includ

原创 usaco 2.1.4 Subset Sums 【母函數】

(1+x)*(1+x^2)*(1+x^3)*……*x^n   則 x^(n*(n+1)/2) 的係數一半爲ans/* ID: w.x.f.g1 PROG: subset LANG: C++ */ #include<iostre

原创 poj 1365 Prime Land 【簡單數論】

#include<iostream> #include<sstream> #include<cstdio> #include<vector> using namespace std; bool not_prime[40000]; vect

原创 HDU 3589 Jacobi symbol 【二次剩餘】

#include<cmath> #include<iostream> using namespace std; const int maxn=1000000+10; typedef long long ll; bool not_pri[

原创 hdu3590 PP and QQ 【ext_anti-nim】

anti-nim 博弈擴展(樹形博弈) 詳細見:http://wenku.baidu.com/view/e0c822d3240c844769eaeea8.html #include<iostream> #include<cstring>

原创 HDU 3561 How many times 【計算幾何】

判斷任兩圓的交點和每個圓的圓心即可 #include<iostream> #include<vector> #include<math.h> using namespace std; #define eps 1e-8 const int

原创 poj 3261 Milk Patterns 【後綴數組】

給定一個字符串,求至少出現 k 次的最長重複子串,這 k 個子串可以重疊。 算法分析: 這題的做法和上一題差不多,也是先二分答案,然後將後綴分成若干組。不同的是,這裏要判斷的是有沒有一個組的後綴個數不小於 k。如果有,那麼存在k 個相同的

原创 hdu3584 Cube【三維樹狀數組】

詳細見:http://wenku.baidu.com/view/2175f419ff00bed5b9f31db4.html  更新8個頂點就行了 #include<iostream> #include<cstring> #include

原创 poj 1743 Musical Theme 【後綴數組】

有希望成爲最長公共前綴不小於 k 的兩個後綴一定在同一組。然後對於每組後綴,只須判斷每個後綴的 sa 值的最大值和最小值之差是否不小於k。如果有一組滿足,則說明存在,否則不存在。 #include<cstdio> #include<cst

原创 POJ 3468 A Simple Problem with Integers【線段樹】

#include<iostream> #include<cstdio> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define mid

原创 HDU 4167 User Names【string stl】

#include<iostream> #include<sstream> #include<algorithm> #include<set> using namespace std; int main() { cin.sync_w

原创 HDU 3579 Hello Kiki【中國剩餘】

#include<iostream> using namespace std; typedef long long ll; ll ext_gcd(ll a,ll b,ll &x,ll &y) { if(b==0){x=1;y=0;