原创 旅旅旅遊

題目:旅旅旅遊 題解:分別求出以1爲起點的最短距離,和以n爲起點的最短距離。然後對每條邊進行判斷,判斷這條邊是否爲最短路徑的邊。最後再把剩下的邊判斷一下就好了。 #include <bits/stdc++.h> #include

原创 牛妹吃豆子

題目:牛妹吃豆子 題解:這道題用的二維差分和二維前綴和。 前綴和與差分 #include <bits/stdc++.h> #include <cstdlib> using namespace std; typedef long l

原创 Aragorn's Story

題目:Aragorn’s Story 樹鏈剖分模板 #include <map> #include <set> #include <stack> #include <cmath> #include <vector> #includ

原创 Connections between cities

題目:Connections between cities 題解:這是一個森林,建完森林之後把每一個樹選擇一個點連結到0點,。 判斷x和y的時候,如果x和y的最近公共結點是0,那就說明不是同一個樹。 #include <map>

原创 I I love you

題目:I love you 簡單DP。分析做的每一道DP. 不同的子序列 解法1 #include<iostream> #include<string> using namespace std; typedef long long

原创 Phone List

題目:Phone List 題解:先按照長短從從長到短排序,如果插入一個短的,並且它的結束標誌還有的話,就是NO #include <map> #include <stack> #include <queue> #include

原创 Chip Factory

題目:Chip Factory 題解:這題其實用暴力是可以解決的。但我是爲了練習01字典樹。先將n個數組建成一個01字典樹,我是用num數組來統計有多少個數經過某個結點。然後來一個雙重循環,計算(a[i]+a[j]),但題目要求i

原创 F. Function!

題目:F. Function! 總結:對於b>=a,logba往上取,那麼一定是1。那麼就只需要考慮logab,q =sqrt(n),對於 q+1~n,每一段的答案都是 i*(n-i+1),可以將這個公式分解,就變成i*(n+1)

原创 Jelly

題目:Jelly 題解:運用廣度優先搜索。 #include <iostream> #include <string> #include <cstdio> #include <queue> using namespace std;

原创 Humble Numbers

題目:Humble Numbers 題解:這是一個簡單dp,就是輸出比較麻煩。題目要求的數字是隻能整除2、3、5、7的,所以可以對於第i個數,可以從1~i-1依次遍歷,每個數都可以乘上2、3、5、7,尋找比第i個數大的最小的。 #

原创 IMMEDIATE DECODABILITY

題目:IMMEDIATE DECODABILITY 題解:先按照每個字符串的長短從小到大排序,然後依次插入每一個字符串,並且每一個插完之後,做一下標記,如果下一個字符串訪問到這個標記,則說明Not #include <string

原创 Dividing

題目:Dividing 題解:這是一道多重揹包。採用了二進制拆分。 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N =

原创 C、Xor Path(LCA模板)

題目:C、Xor Path 題解:先求根節點到每個結點的異或值,用pre[x],和pre[y]來表示,假設求結點x和結點y之間最短路徑的異或值,pre[x]和pre[y]之間一定會有重合的部分,但是pre[x]^pre[y],就把

原创 Kuangyeye's Game

題目:Kuangyeye’s Game 題解:判斷點是否共線,是有數學公式的 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef

原创 B. Collecting Packages

題目:B. Collecting Packages 簡單的搜索,爲啥當時沒做出來呢 #include<bits/stdc++.h> using namespace std; typedef long long ll; const