補題連接:Hereios
題意:N 個不同的糖,請問有多少種分法給 A,B兩人c++
水題,寫幾組狀況就能知道輸出 \(N - 1\) 便可spa
題意:給定一個字符串,問是否能夠在字符串前加若干個 0
使字符串迴文code
先判斷一下字符串迴文否?自己就回文就無需處理,否則字符串後面有幾個 0
就加上多少,而後再判斷ci
題意:在一個二維座標軸上,給定一個長度 R
,請問是否有最小步數(每步只能走 R,但座標能夠非整數)到達 \((X,Y)\)字符串
思路:get
假設 \(d\) 爲 起點\((0,0)\) 至 \((X,Y)\) 的歐幾里得距離,則容易想到如下三種狀況string
其實這裏 第一種狀況和第三種狀況可合併寫:
ceil(d / R)
it
void solve() { double R, X, Y; cin >> R >> X >> Y; double d = sqrt(X * X + Y * Y); if (d < R) cout << 2; else cout << ceil(d / R); }
題意:給定 \(3\) 個字符串 \(N_1,N_2,N_3\) 試問是否有數字能代替某種字母使得 \(N_1 + N_2 = N_3\)io
思路:
首先,若是出現 \(10\) 種以上的字母,那麼確定是沒法解決的,直接輸出 UNSOLVABLE
便可
對於剩下的狀況來講,能夠嘗試把數字分配給字母,而後 check 一下 \(N_1 + N_2 = N_3\) 。
\(10 ! = 3628800\) 是可執行範圍內
注意別給首位分配 \(0\) 便可
void solve() { map<char, int> ch; string s, t, w; cin >> s >> t >> w; for (char c : s) ch.emplace(c, 0); for (char c : t) ch.emplace(c, 0); for (char c : w) ch.emplace(c, 0); if (ch.size() > 10) { cout << "UNSOLVABLE"; return; } int p[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; do { string a, b, c; int i = 0; for (auto it = ch.begin(); it != ch.end(); ++it, i++) it->second = p[i]; for (char x : s) a.push_back(ch[x] + '0'); for (char x : t) b.push_back(ch[x] + '0'); for (char x : w) c.push_back(ch[x] + '0'); ll A = stoll(a), B = stoll(b), C = stoll(c); if (a[0] != '0' && b[0] != '0' && c[0] != '0' && A + B == C) { cout << a << "\n" << b << "\n" << c << "\n"; return; } } while (next_permutation(p, p + 10)); cout << "UNSOLVABLE"; }
題意:
思路:用 DFS 搜索一下便可
// Murabito-B 21/04/12 #include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100005; int n, c[N], cnt[N], good[N]; vector<int> to[N]; void dfs(int u, int fa) { if (cnt[c[u]] == 0) good[u] = 1; cnt[c[u]]++; for (int i = 0, v; i < to[u].size(); i++) if ((v = to[u][i]) != fa) dfs(v, u); cnt[c[u]]--; } void solve() { cin >> n; for (int i = 1; i <= n; ++i) cin >> c[i]; for (int i = 1, u, v; i < n; ++i) cin >> u >> v, to[u].push_back(v), to[v].push_back(u); dfs(1, 0); for (int i = 1; i <= n; ++i) if (good[i]) cout << i << "\n"; } int main() { ios_base::sync_with_stdio(false), cin.tie(0); solve(); return 0; }
F題表示是懵逼的,作不來