POJ – 2763 Housewife Wind 【LCA 樹狀陣列 or 樹鏈剖分】
傳送門 題目大意: 知道了一顆有 n 個節點的樹和樹上每條邊的權值,對應兩種操作: 0 x 輸出 當前節點到 x節點的最短距離,並移動到 x 節點位置 1 x val 把第 x 條邊的權值改為 val 思路: 樹上兩個節點a,b的距離可以轉化為 dis[a] dis[b] – 2*dis […]
-->
程式前沿 幫助程式設計師解決問題,增加專業技能,提升個人能力與未來世界競爭力。
傳送門 題目大意: 知道了一顆有 n 個節點的樹和樹上每條邊的權值,對應兩種操作: 0 x 輸出 當前節點到 x節點的最短距離,並移動到 x 節點位置 1 x val 把第 x 條邊的權值改為 val 思路: 樹上兩個節點a,b的距離可以轉化為 dis[a] dis[b] – 2*dis […]
傳送門 題意: 先給一棵具有n個節點的樹, 然後再給出m條邊, 問從樹上刪去一條邊, 再從m條邊中刪去一條邊, 把這個圖分成至少兩部分的方案數. 思路 我們知道再樹上每加一條邊樹上一定有環, 假設我們將在環上的樹邊的累加標記都加一, 表示被一條m中的邊所覆蓋, 然後我們在分析, 對於一顆樹我們刪去任 […]
#include<iostream> #include<algorithm> #include<vector> #include<string> using namespace std; void countfreq(string s,vector&l […]
我自己的思路,順便複習快排 #include<iostream> #include<string> #include<vector> using namespace std; int getcount(string s,int len){//求逆序數 int co […]
藉助stl的priority_queue實現哈夫曼樹的思想。換成__int64後AC #include<iostream> #include<queue> using namespace std; int main(){ __int64 n,k; cin>>n; […]
#include<iostream> #include<cstring>///memset #define top 1000001 using namespace std; bool isPrime[top]; void getIsPrime(){ memset(isPrim […]
網上都是二分搜尋答案 其實過程也可以二分搜尋 洛谷有個扔瓶蓋 一樣的 #include <iostream> #include <algorithm> using namespace std; const int MAXN = 1e5 50; int cow[MAXN] = […]
Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cook […]
由於英語極差,看了半天也沒看懂題目,最後參考了其他人的題解才搞懂題目,我就直接把題意貼過來了 題意:這道題目只是題意自己就去理解了半天,大概題意如下:給出i一個n*n的矩陣,初始化為均為0,還有關於這個矩陣的幾種操作,操作如下:命令1:(X Y A)對位於座標(X Y)的 […]
#include<cstdio> #include<cmath> #include<algorithm> #define eps 1e-8 #define max(x,y) (((x)>(y))?(x):(y)) using namespace std; i […]