原題連結
這道題目的思維還是有點難度的,但是code寫起來非常精簡,官方提供的構造解法甚至hasEdge裡只須要寫1行......有興趣的可以到IOI2014網站去膜拜一下。
2016年4月12日 星期二
2016年3月11日 星期五
[Wunder Fund Round 2016 pD][DP] Hamiltonian Spanning Tree
link
You can view official tutorial here.
Here I will explain some points I consider important when trying to solve the problem.
There may be some mistakes in grammar due to my poor English QAQ.
Any correction of algorithm or grammar is welcomed.
It's not hard to find that x>y and x<y are two different problem: One is to use more tree edges as possible while the other is to use less tree edges.
You can view official tutorial here.
Here I will explain some points I consider important when trying to solve the problem.
There may be some mistakes in grammar due to my poor English QAQ.
Any correction of algorithm or grammar is welcomed.
It's not hard to find that x>y and x<y are two different problem: One is to use more tree edges as possible while the other is to use less tree edges.
2016年3月4日 星期五
2016年3月3日 星期四
[Codeforces Round #218 (Div. 2) pD][Disjoint Set] Vessels
原題連結
一道並查集的頗直覺的題目
難點大概就只有在有沒有想到要用Disjoint Set去做吧......
對於已經滿的vessel i ,執行 fa[i] <- findset(i+1) ,直觀上就是將每個相鄰的滿vessel連接起來,已達到快速查詢可用vessel的效果。
細節上要注意水流到地上的case要做好,不然很容易WA或是TLE。
一道並查集的頗直覺的題目
難點大概就只有在有沒有想到要用Disjoint Set去做吧......
對於已經滿的vessel i ,執行 fa[i] <- findset(i+1) ,直觀上就是將每個相鄰的滿vessel連接起來,已達到快速查詢可用vessel的效果。
細節上要注意水流到地上的case要做好,不然很容易WA或是TLE。
#include<cstdio> #define LL long long using namespace std; const int maxn=200000+5; int fa[maxn],cap[maxn],cur[maxn]; int findset(int x) {return x==fa[x]?x:fa[x]=findset(fa[x]);} int main() { int n,m; scanf("%d",&n); for(int i=0;i<n;i++) {fa[i]=i;scanf("%d",cap+i);} fa[n]=n; scanf("%d",&m); for(int i=0,type,a,b;i<m;i++) { scanf("%d",&type); if(type==1) { scanf("%d%d",&a,&b);a--; a=findset(a); for(;b && a!=n;) { if(cap[a]-cur[a]>b) cur[a]+=b,b=0; else // cap[a]-cur[a]<=b { b-=cap[a]-cur[a]; cur[a]=cap[a]; fa[a]=findset(a+1); a=findset(a); } } } else { scanf("%d",&a);a--; printf("%d\n",cur[a]); } } }
2016年3月2日 星期三
2016年3月1日 星期二
2016年2月24日 星期三
[POI XI Stage II][SCC] The Tournament
原題連結
我個人非常喜歡這道題,主要是因為直到我AC前的2個小時,我都完全沒想到這題是SCC的一道題XD。
最後雖然發現了和SCC的強大關聯性,還是借用了同學的code,而且想了非常久才弄出來的......
我個人非常喜歡這道題,主要是因為直到我AC前的2個小時,我都完全沒想到這題是SCC的一道題XD。
最後雖然發現了和SCC的強大關聯性,還是借用了同學的code,而且想了非常久才弄出來的......
2016年2月23日 星期二
2016年2月22日 星期一
2016年1月26日 星期二
[Codeforces 100495A][2014 KTU ACM ICPC Qualification Round][Dijkstra] Crystals
原題連結
注意到因為n很小...所以對於任何一個水晶集合都可以將狀態用一個int表示出來(點),然後將集合的變換看成狀態的轉移(邊)
那麼本題就可以套用經典的最短路算法解決O(NlogN),此時N=(2^n)
注意到因為n很小...所以對於任何一個水晶集合都可以將狀態用一個int表示出來(點),然後將集合的變換看成狀態的轉移(邊)
那麼本題就可以套用經典的最短路算法解決O(NlogN),此時N=(2^n)
訂閱:
文章 (Atom)