A
#include <bits/stdc++.h> using namespace std; int a, b , n, c; int main() { cin >> a >> b >> n; for (int i = 1; i <= n; ++i) { cin >> c; cout << c << ' '; int res = 0; if (c <= 1000) res = c * a; else res = 1000 * a + (c - 1000) * b; cout << res << '\n'; } return 0; }
B
#include <bits/stdc++.h> #define P pair<int, int> using namespace std; P p[26]; int n; char a[25], b[25]; int is(int a, int b) { int x = abs(p[a].first - p[b].first), y = abs(p[a].second - p[b].second); if (x + y == 0) return 1; if (x <= 1 && y <= 1) return 2; return 3; } int main () { for (int i = 0; i <= 8; ++i) p[i] = {0, i}; for (int i = 9; i <= 17; ++i) p[i] = {1, i - 9}; for (int i = 18; i <= 25; ++i) p[i] = {2, i - 18}; cin >> n; while (n--) { int ans = 0; cin >> a + 1 >> b + 1; for (int i = 1; a[i] || b[i]; ++i) { if ((!a[i] && b[i]) || (!b[i] && a[i])) ans = 3; if (ans == 3) break; ans = max(ans, is(a[i] - 'a', b[i] - 'a')); } cout << ans << '\n'; } return 0; }
C
#include <bits/stdc++.h> #define ll long long using namespace std; int t, n, k; int main() { cin >> t; while (t--) { ll ans = 0, c, d; cin >> n >> k >> c; while (--k) { cin >> d; ans += min((c + n - d + 1) % n, (d - c - 1 + n) % n); c = d; } cout << ans << '\n'; } return 0; }
D(广搜)
#include <bits/stdc++.h> #define P pair<int, int> #define PP pair<int, P> #define inf 1e9 using namespace std; int t, n, a[121], mp[121][81]; priority_queue<PP, vector<PP>, greater<PP> > q; void updown(int x, int y, int aa, int cur, int c) { if (x < 1 || x > n) return; y = min(y, a[x]); if (mp[x][y] > cur + 1) { mp[x][y] = cur + 1; q.push({ mp[x][y], {x, y} }); } y = a[x] * aa; if (mp[x][y] > c + cur + 1) { mp[x][y] = c + cur + 1; q.push({ mp[x][y], {x, y} }); } } int main() { cin >> t; while (t--) { cin >> n; memset(mp, 0x7f7f, sizeof mp); priority_queue<PP, vector<PP>, greater<PP> >().swap(q); for (int i = 1; i <= n; ++i) cin >> a[i]; int x, y, lx, ly, ans = inf; cin >> x >> y >> lx >> ly; q.push({ 0, {x, y} }); mp[x][y] = 0; while (!q.empty()) { int cur = q.top().first; if (cur >= ans) break; P p = q.top().second; q.pop(); if (p.first == lx) ans = min(ans, abs(ly - p.second) + cur); updown(p.first - 1, p.second, 1, cur, p.second); updown(p.first + 1, p.second, 0, cur, a[p.first] - p.second); } cout << ans << '\n'; } return 0; }
E(就是对三角函数的应用)
#include <bits/stdc++.h> #define PI 3.141592653589793 using namespace std; int t, w, a, b, c, n; int calc(double x, double y) { double r = x * x + y * y; if (r < a * a) return 1; if (r < b * b) return 2; if (r < c * c) return 3; return 4; } int main() { cin >> t; while (t--) { cin >> w >> a >> b >> c >> n; double g = 2 * PI / w; int ans = 0; while (n--) { double x, y; cin >> x >> y; double angle = atan(abs(y/x)); if (x < 0 && y > 0) angle = PI - angle; else if (x < 0 && y < 0) angle += PI; else if (x > 0 && y < 0) angle = PI * 2 - angle; int ww = ceil(angle / g), r = calc(x, y); if (r == 1) {ans += 50; continue;} else if (r == 2) ans += 2 * ww; else if (r == 3) ans += ww; } cout << ans << '\n'; } return 0; }
I
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 1e5 + 5; int t, n, a[maxn], p[maxn]; ll c[maxn]; void add(int x, int y) { for (; x <= n; x += -x & x) c[x] += y; } ll ask(int x) { ll ans = 0; for (; x; x -= x & -x) ans += c[x]; return ans; } int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; ++i) cin >> a[i], p[a[i]] = i, add(i, a[i]); int cur = a[1]; ll ans = 0; for (int i = 1; i <= n; ++i) { ll x = ask(p[i] - 1) - ask(p[cur] - 1); ll y = ask(p[cur] - 1) - ask(p[i] - 1); if (p[i] < p[cur]) x += ask(n); if (p[i] > p[cur]) y += ask(n); add(p[i], -i); cur = i; ans += min(x, y); } printf("%lld\n", ans); } return 0; }