Time of Update: 2018-12-06
http://poj.org/problem?id=1958做的第一個題目給演算法的題。過程說的很明了,先把n-k個用四個柱子的方法移動到B,再把k個用三個柱子的方法移動到D,最後把n-k個用四個柱子的方法移動到D。n-k個共移動了兩次,三個柱子移動的最少步數我們知道為2^n-1,總的移動步數即為f[i-j]*2+t[j],得轉移方程f[i] = Min(f[i],
Time of Update: 2018-12-06
http://poj.org/problem?id=1606猛一看沒思路,仔細想想,記住當前a,b水量及操作就可以bfs了,純粹的暴力啊。。輸出需要路徑,要在node中用指標記錄目前狀態的前一狀態,根據oper輸出即可。code:#include<cstdio>#include<cstring>int a, b, n, h, r ;bool vis[1001][1001] ;int ans[100001] ;struct node{ int va, vb, oper
Time of Update: 2018-12-06
http://acm.fzu.edu.cn/problem.php?pid=1894簡單單調隊列。code:#include<cstdio>int data[1000001] ;int queue[1000001] ;int num[1000001] ;int h, r, n ;void insert(){ if(r==h-1||data[n]<queue[r]){ r ++ ; queue[r] = data[n] ; num[
Time of Update: 2018-12-06
http://poj.org/problem?id=2823純粹的單調隊列練習題,用了一下輸入的加速,結果發現還不如scanf快...話說前段時間搞單調最佳化的時候,就是有點卡在單調隊列上了,當時真沒整明白資料裡說的到底在維護什麼...今天費老傳了DP資料(完整版...)才算真搞懂。唉,浪費了那麼多激情... 為DP的單調最佳化做準備吧,明天開始搞DP了,不能再縮了... code: #include<cstdio>int data[1000005] ;int queue[10000
Time of Update: 2018-12-06
http://poj.org/problem?id=2912枚舉+關係並查集,並查集與1182相似,枚舉每個小孩為judge時的情況,若當前枚舉情況下每個round都是正確的,則當前枚舉編號可能是judge。若只找到一個judge的可能,則找出排除其他編號所需最多的round數,兩者即為輸出。做了一整天,WA了9次,原因是位移量r公式搞錯一個地方,列了好多次表才搞定。code:#include<cstdio>#include<cstring>using namespace
Time of Update: 2018-12-06
http://poj.org/problem?id=1182重點依舊是用rank記錄相對於根節點的關係,並及時跟新rank的值。code:#include<cstdio>using namespace std ;int f[50001] ;int r[50001] ;//與根節點的關係int find_Set(int x){ int temp ; if(x==f[x]) return x ; temp = f[x] ; f[x] = find_S
Time of Update: 2018-12-06
http://poj.org/problem?id=3600枚舉subimage第一行在image中的位置,然後在image中選取c列,若這c列中有r行和subimage相同,那麼即為有解。code:#include<cstdio>#include<cstring>#include<iostream>using namespace std ;int vis[21] ;char smap[21][21], imap[21][21] ;int r, c, R, C
Time of Update: 2018-12-06
http://poj.org/problem?id=2503思路很簡單,對foreign language word建trie樹,插入時一併傳入word的序號,與english word相對應。尋找時直接尋找word標記的序號,從儲存數組中輸出englishword就好了。比較蛋疼的是這題的輸入,一開始真心搞不定啊。。搞定後直接1Y。code:#include<cstdio>#include<cstring>char str[100001][11] ;//模式串char
Time of Update: 2018-12-06
http://poj.org/problem?id=1222和poj 1753類似,1753是求全0或全1的步數,這題是求全0的解決方案。當時是拿1753的代碼改的,枚舉步數,最多30步,這樣的話狀態總量就是2^30。。。枚舉第一行狀態,共2^6,第一行確定了便可確定其餘行,最後看末行是否全為0即可。code:#include<cstdio>#include<cstring>int map[5][6], ans[5][6] ;int tur[5][2] = {0, 0,
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2972i為當前第幾段,j為跑完第i段剩餘的體力。第i段有三種跑法可選: 第一種要消耗f1的體力,所以保證j+f1<=m。dp[i][j] = min(dp[i][j], dp[i-1][j+f1]+t1) ;第二種不消耗體力。 dp[i][j] = min(dp[i][j], dp[i-1][j]+t2) ;第三種增加f2的體力,保證j-f2>=0。dp[i][
Time of Update: 2018-12-06
http://poj.org/problem?id=2236給定N個壞掉的無線發射器座標,給定其能相連通的最大距離,O i 代表修好第i個發射器,S i j 表示判斷第i個和第j個是否能接通(可間接相連)。簡單並查集應用,一個bool數組標記是否可用,每修好一個,找N個中已修好且可以直接相連的合并。最後判斷i,j
Time of Update: 2018-12-06
http://poj.org/problem?id=3294
Time of Update: 2018-12-06
http://poj.org/problem?id=3411這題RE了N多次,到最後也不知道是什麼原因。看到網上說vis[x]不會超過3,就試著加上了<=3的限制,我了個去,馬上AC!問題應該還是遞迴過程爆棧了吧。code:#include<cstdio>#include<cstring>const int MAX = 99999999 ;int vis[15] ;int ans, n, m ;bool flag ;struct node{ int a ;
Time of Update: 2018-12-06
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1089遞迴實現的排列組合。code:#include<cstdio>int data[20] ;int ans[6], n ;void work(int diex, int aiex){ int i ; if(aiex==6){ for(i=0; i<5; i++) printf("%d ", ans[i])
Time of Update: 2018-12-06
http://poj.org/problem?id=1655同poj3107,只要求輸出一個數值最小的點。剛開始的答案值修改的num[]記錄的,罪過罪過。。。 code:#include<cstdio>#include<cstring>#define Max(a, b) a>b?a:busing namespace std ;const int MAX = 20001 ;int k, n, Min, anspoint, ansnum ;int vis[MAX],
Time of Update: 2018-12-06
http://poj.org/problem?id=1260很明顯的,當vi<vj<vk且i可以用j來代替(即(si+10)*vi<si*vj)時,則當前解為最優解(因為si*vj<si*vk - -...)。用dp[j]表示前j種pearl的最小代價,i>j&i=1...n,dp[1]=(s1+10)*v1,用第i種pearl替代前i-j種,得狀態轉移方程:dp[i] = min(dp[j] + (sum[i]-sum[j]+10)*val[i])
Time of Update: 2018-12-06
http://poj.org/problem?id=1984 題目描述的如此蛋疼。。。
Time of Update: 2018-12-06
http://poj.org/problem?id=1159卡記憶體的題比卡時間的題還要噁心!用int類型提交就MLE,只能換成short int,65128K,Memory
Time of Update: 2018-12-06
http://poj.org/problem?id=3107 給定一棵樹,取去掉某一節點後形成子樹的最大節點數,求使這個數最小的節點。去掉某一節點後,形成的樹包括子樹和原樹去掉以這個點為根的樹所形成的樹,在這幾個樹中求最大值即可。節點數的計算可用回溯,過程中選取最大值。貌似是我第一個用鄰接表存邊的題,貼下模板。鄰接表存邊code:#include<iostream>#include<cstring>#include<cstdio>using namespace
Time of Update: 2018-12-06
http://poj.org/problem?id=2157算是細節比較多的搜尋題了吧,考慮的時間比較長,最終代碼寫的也是那麼的糾結。。。去真的不知道為什麼RE啊!重新敲了一遍,完全一樣的思路,然後就A掉了!搞毛啊?!白白浪費一下午找bug啊...#include<cstdio>#include<cstring>int key[6], temkey[6] ;int tur[4][2] = {0, 1, 0, -1, 1, 0, -1, 0} ;bool vis[21][2