Time of Update: 2018-12-06
http://poj.org/problem?id=2485題不難,題目很難...讀了好幾遍還是給理解錯了,糾結!就是求最小產生樹裡最大的邊權值,拿過來poj1287一改就交,果斷WA..仔細一看,權值的更新給搞錯了,這是要讓我鬱悶到極點啊!#include<cstdio>#define Max(a, b) a>b?a:b#define Min(a, b) a>b?b:ausing namespace std ;int map[505][505] ;int dis
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2058一道簡單的找規律題。每一行中的兩個相鄰字元必定不同。 行從1開始,偶數行的'@'和'*'必定各佔一半,奇數行分兩種情況,若不全為'?',此行中第一個不為'?'的字元及其下標的奇偶決定'@'個數,若為'@'且下標為奇則'@'為i/2+1,反則為i/2。code:#include<cstdio>#include<iostream>#include&
Time of Update: 2018-12-06
http://poj.org/problem?id=3450假期做過這題,當時是用KMP做的,這次用尾碼數組。 把n個字串串連起來,中間用不同的且輸入串中不會出現的字元隔開,對新產生串的每個字元根據所在原子串劃分地區,用Loc數組標記。二分公用子串長度,尋找相鄰的尾碼中是否有連續n個尾碼的height值大於枚舉值,且分屬於n個不同的串。code:#include<cstdio>//最長公用子串#include<cstring>#define Max(a, b) a&g
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004用到的主要是回溯,遞迴時先將所有字元放入棧中,在回溯時判斷字元是否出棧並記錄路徑。棧是用字元數組類比的。另外這題的輸出有點扯,每一行的最後一個i或o後面是有空格的,不需要處理,PE一次。code:#include<cstdio>#include<cstring>using namespace std ;char str[50] ;char bs
Time of Update: 2018-12-06
http://poj.org/problem?id=2385 dp[i][j], i為第幾分鐘,j為走了幾次。則dp[i,j]=max(dp[i-1,j-1],
Time of Update: 2018-12-06
http://poj.org/problem?id=3661到達終點的方式有兩種,一是從n-1走到n,二是從某一節點休息到n。dp[i][j],i代表第幾分鐘,j代表當前忍耐度。對於第一種情況,dp[i][j]=dp[i-1][j-1] + d[i] ;第二種情況,dp[i-1][0]已經計算出來,設dp[i][0]初值為dp[i-1][0],也就是說在i-1分鐘忍耐度為0時繼續休息到i。那麼dp[i][0] = Max(dp[i][0], dp[i-k][k])
Time of Update: 2018-12-06
http://poj.org/problem?id=3450沾3080的光,這題讓我WA了N多次!看到兩個題一樣,買一送二啊,上手就做,悲劇了。。主要是沒考慮一個字元時的情況,改來改去,最後終於想起來把KMP中的m初始化成-1就OK了。我這腦子是鏽掉了嗎?忙活3個小時最後改了一個數就行了,糾結啊!code:#include<cstdio>#include<cstring>int next[201] ;char substr[201] ;char str[4001][201
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=3065 AC自動機,主要注意的就是兩個特徵碼的重疊情況。code:#include<iostream>#include<cstring>#include<cstdio>using namespace std ;const int kind = 30;struct node{ node *fail ; node *next[kind] ; int count
Time of Update: 2018-12-06
http://poj.org/problem?id=3080還是和3450一樣的。code:#include<cstdio>//最長公用子串#include<cstring>#define Max(a, b) a>b?a:bconst int maxn = 650 ;int wa[maxn], wb[maxn], wv[maxn], ws[maxn], rank[maxn], height[maxn], sa[maxn], s[maxn], loc[maxn]
Time of Update: 2018-12-06
http://poj.org/problem?id=1703跟2492基本一樣,不多說。code:#include<cstdio>using namespace std ;int f[100005] ;int r[100005] ;int n, m ;int find_Set(int x){ int temp ; if(x==f[x]){ return x ; } temp = f[x] ; f[x] = find_Set(temp) ;
Time of Update: 2018-12-06
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int nMax=1000;class edge{ public: int v,nex;};edge e[nMax];int n,k,head[nMax]; //head[i]是以點i為起點的鏈表頭部void addedge(int a,int b){
Time of Update: 2018-12-06
http://poj.org/problem?id=1743
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1428
Time of Update: 2018-12-06
http://poj.org/problem?id=3009其實一開始就想把dir當作參數,根據map條件搜尋,但是卻是在遞迴中用while處理的,處理不好map由0變1的回溯.蛋疼的代碼,看著就糾結。。code:#include<cstdio>#include<cstring>#define Min(a, b) a>b?b:a#define MAX 1e+6int tur[4][2] = {0, 1, 0, -1, 1, 0, -1, 0} ;int map[
Time of Update: 2018-12-06
http://poj.org/problem?id=2251刷水題好爽!但是別真跟xcy說的一樣,把rp都給用完了...三維空間的bfs,只是搜尋的時候多了兩個方向而已。code:#include<cstdio>#include<cstring>bool vis[31][31][31] ;int lve[6] = {1, 0, 0, 0, 0, -1} ;int row[6] = {0, -1, 0, 0, 1, 0} ;int col[6] = {0, 0, -1, 1
Time of Update: 2018-12-06
http://poj.org/problem?id=1226 求給定的字串及其反串的最大公用子串。 尾碼數組,將所有的字串及其子串聯接起來,用分隔字元隔開,並給每個字串及反串的字元標記所在串。二分答案,看是否有n個字串或者其反串存在長為mid的公用首碼。code:#include<cstdio>#include<cstring>#define Max(a, b) a>b?a:bconst int maxn = 10001 ;int wa[maxn],
Time of Update: 2018-12-06
http://acm.hdu.edu.cn/showproblem.php?pid=2896這題WA了好多好多次,大概8、9次吧,從cf進行到一半就開始在這調。經過不懈的努力終於發現,TMD,vis的memset放錯地方了!!!這都什麼事啊,老被這種錯給整的那麼鬱悶。。。code:#include<iostream>#include<cstring>#include<cstdio>using namespace std ;const int kind = 13
Time of Update: 2018-12-06
http://poj.org/problem?id=3211小兩口洗衣服,只有一種顏色的衣服洗完才能洗下一種顏色,兩人同時洗問需要的最小時間。這裡一種顏色的衣服所需的總時間可以求出,求出每種顏色衣服所需最小時間便求出了ans。每種顏色的衣服總時間有了,讓求兩個人最短完成時間,就相當於給你一個數讓你分成兩份,並讓這兩份儘可能的小,顯然這個數的一半就是答案。在這裡也就是兩個人洗衣服的時間儘可能相同。怎麼讓一個人洗衣服的時間儘可能等於總時間的一半呢?01背包,最大容量為sum[i]/2,儘可能將背封
Time of Update: 2018-12-06
http://poj.org/problem?id=3256對N個牧場用鄰接表格儲存體路徑,記錄下每個牧場初始牛的數目,沿路徑dfs求連通牧場的牛數和。code:#include<cstdio>#include<cstring>using namespace std ;int num[1001] ;int sum[1001] ;int head[1001] ;bool vis[1001] ;int x ;struct past{ int v, nex ;}edge[
Time of Update: 2018-12-06
http://poj.org/problem?id=1308題意:給出一些節點的串連情況,問所給出的節點是不是可以構成一棵樹。樹的定義已經給出:1.只有一個根節點2.根節點到每個節點只有唯一路徑3.題目第一句特別提到空樹也是一顆合法樹對於第一條,明顯的森林不是樹,並查集將每對輸入合并,最後看是否在同一個集合中。第二條,保證唯一路徑與題目中給出的第二條定義相似,對於每個節點,只有一條邊指向它。如果節點已經存在於集合中,則肯定已經有一邊指向它,或者它是作為根節點。也就是說,輸入的兩個元素不能在同一個