#include<bits/stdc++.h> usingnamespace std; intmain(){ int n; cin >> n; double x = 0; for (int i = 0; i < n; i++) { double a; cin >> a; x += 1.0 / a; } printf("%.2lf\n", 1.0 / (x / n)); }
L1-5 情人节
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<bits/stdc++.h> usingnamespace std; intmain(){ vector<string> v; string s; while (cin >> s, s != ".") { v.push_back(s); } if (v.size() >= 14) { cout << v[1] << " and " << v[13] << " are inviting you to dinner...\n"; } elseif (v.size() >= 2) { cout << v[1] << " is the only one for you...\n"; } else { cout << "Momo... No one is for you ...\n"; } }
#include<bits/stdc++.h> usingnamespace std; intmain(){ int n, m; cin >> n >> m; vector<vector<int>> G(n + 1, vector<int>(n + 1, 0)); for (int _ = 0; _ < m; _++) { int u, v, w; cin >> u >> v >> w; G[u][v] = G[v][u] = w; } int T; cin >> T; int cnt = 0; pair<int, int> ans = {0, 1e9}; for (int id = 1; id <= T; id++) { int k; cin >> k; vector<int> a; set<int> s; a.push_back(0); for (int i = 0; i < k; i++) { int x; cin >> x; a.push_back(x); s.insert(x); } a.push_back(0); int sum = 0; bool ok = true; for (int i = 1; i < a.size(); i++) { if (!G[a[i - 1]][a[i]]) ok = false; sum += G[a[i - 1]][a[i]]; } if (ok && s.size() == n && k == n) { cnt++; if (ans.second > sum) { ans = {id, sum}; } } } cout << cnt << '\n'; cout << ans.first << ' ' << ans.second; }
structBIT { int n; vector<int> tr; BIT(int n) : n(n), tr(n + 1, 0) {} voidadd(int i, int d){ for (; i <= n; i += (i & -i)) tr[i] += d; } intget(int i){ int s = 0; for (; i; i -= (i & -i)) s += tr[i]; return s; } intkth(int k){ int l = 0, r = n + 1, mid; while (r - l > 1) (get(mid = (l + r) >> 1) < k) ? l = mid : r = mid; return r; } };
intmain(){ int n; cin >> n; BIT bit(1e5); stack<int> s; while (n--) { string op; cin >> op; if (op == "Pop") { if (s.empty()) { cout << "Invalid\n"; } else { bit.add(s.top(), -1); cout << s.top() << '\n'; s.pop(); } } elseif (op == "Push") { int x; cin >> x; bit.add(x, 1); s.push(x); } else { if (s.empty()) { cout << "Invalid\n"; } else { int k = (s.size() + 1) / 2; int val = bit.kth(k); cout << val << '\n'; } } } }