質因數分解 + 模運算 + 等比級數 解法 先求出題目中 A 的質因數分解, 每個 A 的因數和可以用以下公式求得: 其中, 分別代表 A 的質因數、對應的次方,要算出 裡面的值,需要在取模底下做運算,所以需要模反元素、模底下的快速冪。 但是這種運算,在某些情況下,取模計算 有可能輸出 1 (非法), 這種情況,不可以直接像上面計算等比級數,就必須遞迴解等比級數。 計算方式在程式碼中。 (summ 函式) 傳送門 POJ1845 程式碼 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 ... Read more 10 Jul 2017 - 1 minute read
反向 LCS 因為找到反向字串與原字串的 LCS ,就代表找到原字串中,最長的回文子序列, 將這個 LCS 長度減去原字串長 == 最少要插入的字元,使得整個字串變成回文。 需要留意記憶體大小 傳送門 POJ1159 程式碼 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #pragma GCC optimize("O3") #pragma GCC target ("avx") #include <iostream> #include <iomanip> #include <algorithm> #i... Read more 10 Jul 2017 - less than 1 minute read
最大流、二分圖匹配 解法 最大流,人配對星球,看看人 -> 星球的最大流是否可以 >= 目標(人數) 傳送門 HDU3605 程式碼 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 9... Read more 10 Jul 2017 - 2 minute read
線段樹水題 傳送門 HDU1166 程式碼 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 #... Read more 10 Jul 2017 - 2 minute read
就是單純爬行法 傳送門 POJ3061 程式碼 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) { int T; vector<int> seq; cin >> T; wh... Read more 27 Jun 2017 - less than 1 minute read