9.3美团笔试C++代码参考
AK代码,仅供参考,虽然之前投实习的笔试也AK了但没发面试😭感觉美团还是看学历吧
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << max({0, b - a + 2, 11 - a}); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10; int n, d[N], res[N]; map<int, int> idx; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &d[i]); idx[d[i]] = i; } int cur = 0; for (auto it : idx) { res[it.second] = cur; if (cur == it.first) { cur++; } } for (int i = 1; i <= n; i++) printf("%d ", res[i]); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10; int n, res[N], x; vector<int> g[N]; char d[N]; bitset<30> b[N]; void dfs(int u) { for (int ne : g[u]) { dfs(ne); } b[u][d[u] - 'A'] = 1; for (int ne : g[u]) { b[u] |= b[ne]; } } int main() { scanf("%d", &n); for (int i = 2; i <= n; i++) { scanf("%d", &x); g[x].push_back(i); } scanf("%s", d + 1); dfs(1); for (int i = 1; i <= n; i++) { printf("%d ", (int)b[i].count()); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 3e4 + 10; typedef long long LL; int n, m, k, x; LL c[N], a[N], b[N]; LL f[N]; struct node { int l, r; LL v; } tr[N << 2]; void pushup(int u) { tr[u].v = max(tr[u << 1].v, tr[u << 1 | 1].v); } void build(int u, int l, int r) { tr[u] = {l, r, 0}; if (l == r) { tr[u].v = f[l]; return; } int mid = (l + r) >> 1; build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r); pushup(u); } LL query(int u, int l, int r) { if (l > r) return -1e18; if (l <= tr[u].l && tr[u].r <= r) { return tr[u].v; } int mid = (tr[u].l + tr[u].r) >> 1; LL res = -1e18; if (l <= mid) { res = max(res, query(u << 1, l, r)); } if (mid < r) { res = max(res, query(u << 1 | 1, l, r)); } return res; } void modify(int u, int l, int r, LL x) { if (l <= tr[u].l && tr[u].r <= r) { tr[u].v = x; return; } int mid = (tr[u].l + tr[u].r) >> 1; if (l <= mid) { modify(u << 1, l, r, x); } if (mid < r) { modify(u << 1 | 1, l, r, x); } pushup(u); } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) scanf("%lld", &c[i]); for (int i = 1; i <= m; i++) scanf("%lld", &a[i]); for (int i = 1; i <= m; i++) scanf("%lld", &b[i]); memset(f, -0x3f, sizeof f); f[k] = 0; build(1, 1, n); for (int i = 1; i <= m; i++) { int j = c[i]; f[j] = max(f[j] + a[i], max(query(1, 1, c[i] - 1), query(1, c[i] + 1, n)) + b[i]); modify(1, j, j, f[j]); } printf("%lld", query(1, 1, n)); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e4 + 10; typedef long long LL; typedef unsigned long long ULL; int n, m, k, x; LL c[N], a[N], b[N], res[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) scanf("%lld", &b[i]); for (int i = 1; i <= n; i++) scanf("%lld", &c[i]); sort(a + 1, a + 1 + n); sort(b + 1, b + 1 + n); sort(c + 1, c + 1 + n); for (int i = 1; i <= n; i++) { res[i] = 1; } for (int i = 1; i <= n; i++) { int l = (b[i] + 1) / 2, r = b[i] - 1; //[l,r] res[i] = upper_bound(a + 1, a + 1 + n, r) - lower_bound(a + 1, a + 1 + n, l); //cout << res[i] << " "; } //cout << endl; for (int i = 1; i <= n; i++) res[i] += res[i - 1]; ULL ans = 0; for (int i = 1; i <= n; i++) { int l = (c[i] + 1) / 2, r = c[i] - 1; //[l,r] int rr = upper_bound(b + 1, b + 1 + n, r) - b - 1; int ll = lower_bound(b + 1, b + 1 + n, l) - b; // cout << c[i] << " " << max(0ll, res[rr] - res[ll - 1]) << endl; ans += max(0ll, res[rr] - res[ll - 1]); } printf("%llu", ans); return 0; }#美团笔试##美团#