顛三到四

@apcsd3d4

Public team

Joined on May 25, 2020

  • 下圖為河內塔問題(Towers of Hanoi)的一種,共有A、B、C三個柱子,一開始A柱子可以放個數為3倍數的套環,都是花白灰相間的三種不同顏色套環,每種大小的套環都有三個,花色在上,白色在中,灰色在下。套環依序由上到下的編號分別為1~N,假設每次的移動都只能從柱子的頂端移動一個套環,搬到其他柱子放,而且編號較大的套環永遠都不能放在較小套環的上方。最後要將所有花套環移動到A,白套環移動到B,以及所有灰套環移動到C。請寫出一個程式,輸入套環總數(為 3的倍數,包含花白灰三種套環),計算並輸出所有套環的最佳移動順序(移動次數最少)及其移動次數。 原始版本 將 n 個盤子由 A 移動到 C // // n: 移動盤子數 // from: 來源柱 // to: 目的柱
     Like  Bookmark
  • $2^{k} = n_0^2 + n_1^2 + n_2^2 + n_3^2$ 且 $n_0 \leq n_1 \leq n_2 \leq n_3$ 有 $n_0$ ~ $n_3$ 總共 4 個數字要挑選 int num[4] = {}; int solutions = 0; // // pick() 每個位置挑選數字 // remain: 還剩多少可以分
     Like  Bookmark
  • 範例程式碼 最小成本展開樹(Minimal cost Spanning Tree) Prim 演算法 Kruskal 演算法 單點源最短路徑 Dijkstra 演算法
     Like 2 Bookmark
  • // // AC (32ms, 344KB) // #include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std;
     Like  Bookmark
  • #include <iostream> #include <string> #include <vector> using namespace std; struct Animal { string name; int cnt; };
     Like  Bookmark
  • 以 bitmask 紀錄每個節點前、後要有哪些節點。 如果節點 A 同時出現在節點 B 的前與後表示發生衝突了。 #include <iostream> #include <vector> #include <set> using namespace std; const int R_NO_ANSWER = 0,
     Like  Bookmark
  • graph G { splines="line" rankdir=LR node[shape=circle] {rank=same;1,2} {rank=same;3,4} 0 -- 1 [label=4] 0 -- 2 [label=2] 1 -- 2 [label=1] 1 -- 3 [label=5]
     Like  Bookmark
  • graph G { splines="line" node[shape=circle] {rank=same;1,2} {rank=same;3,4,5,6} 0 -- 1 [label=3] 0 -- 2 [label=1] 1 -- 3 [label=1] 1 -- 5 [label=1] 2 -- 5 [label=7]
     Like  Bookmark
  • digraph G { rankdir=LR splines="line" node[shape=circle] {rank=same;1,2} {rank=same;3,4} 0 -> 1 [label=5] 0 -> 2 [label=-2] 1 -> 3 [label=1] 2 -> 1 [label=2]
     Like  Bookmark
  • digraph G { node[shape=circle] N1 [label=1] N2 [label=2] N3 [label=3] N4 [label=4] N5 [label=5] {rank=source;N2}
     Like  Bookmark
  • graph G { node[shape=circle] {rank=same;0} {rank=same;1,2} {rank=same;3,4,5,6} 0 -- 1 [label=3] 0 -- 2 [label=1] 1 -- 3 [label=1] 1 -- 5 [label=1] 2 -- 5 [label=7]
     Like  Bookmark