指望得分:\(100 + 40 + 0 = 140\)
實際得分:\(0 + 0 + 0 = 0\)node
鬼知道爲何我代碼沒有交上。。自測\(10 + 50 + 0\)……這是心態爆炸的一場考試
\(T1\)敲了\(3\)個小時,寫了\(9kb\),連樣例都過不了,改了改過了樣例迅速離開
\(T2\)只會\(40\),但由於一個點的\(a[i]\)很大,因而水過去了,變成了\(50\)
\(T3\)連看都沒看,\(0\)分滾粗ios
我果是個彩筆c++
模擬題, 一看這長長的題面,就知道是個簡單題(fp嘛我作了三個小時不過樣例能是簡單題?)git
其實我以爲最難的不是別的,就是輸入。。。這麼一大堆字符串,還有\(5\)個位置,仍是兩個隊,如何作到最簡?api
其實這些能夠化做一個總體,咱們很容易想到要用結構體存儲,但複雜的hapigou就是:結構體數組怎麼開?數組
咱們能夠開一個三維的\(a\)數組,存儲兩個隊全部位置全部人的信息,\(a[0]\)就表示\(A\)隊,\(a[1]\)就表示\(B\)隊,\(a[x][1-5]\)就表示\(x\)隊五個位置的信息,\(a[x][y][cnt]\)就表示\(x\)隊第\(y\)個位置的第\(cnt\)名選手,這樣不只好理解,還方便了以後咱們要用到的的排序ui
再者,確定要從實力由高到低的選,每次某個位置換的確定是這個位置剩餘的實力最強的人,因此咱們就能夠直接按照實力把每一個位置的人排序,若是實力相同則編號較小的在前spa
以後咱們就要想怎麼來選人了,要想讓場上全部人的綜合實力最大,咱們要保證換下來的人與在場的人實力的差值最小,因此就能夠在五個位置中找差值最小的位置來換,這樣這道題就完美解決了指針
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int A = 5e5 + 11; const int B = 1e6 + 11; const int INF = 1000; inline int read() { char c = getchar(); int x = 0, f = 1; for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1; for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); return x * f; } struct node { char name[16]; int id, val; } a[2][6][A]; int N, M, T, P, Q; int cnt[2][6], change[2][6]; bool cmp(node a, node b) { return a.val == b.val ? a.id < b.id : a.val > b.val; } inline int check(char s[4]) { if(s[0] == 'p' && s[1] == 'g') return 1; if(s[0] == 's' && s[1] == 'g') return 2; if(s[0] == 's' && s[1] == 'f') return 3; if(s[0] == 'p' && s[1] == 'f') return 4; if(s[0] == 'c') return 5; } inline void add(int dui, char name[16], int pos, int id, int val) { a[dui][pos][++cnt[dui][pos]].id = id; strcpy(a[dui][pos][cnt[dui][pos]].name, name); a[dui][pos][cnt[dui][pos]].val = val; } int main() { N = read(), M = read(), T = read(), P = read(), Q = read(); char s[4], name[16]; int idd, val, dui; for(int i = 1; i <= N + M; i++) { dui = (i <= N ? 0 : 1); scanf("%s %d %s %d", name, &idd, s, &val); add(dui, name, check(s), idd, val); } for(int i = 1; i <= 5; i++) sort(a[0][i] + 1, a[0][i] + cnt[0][i] + 1, cmp), sort(a[1][i] + 1, a[1][i] + cnt[1][i] + 1, cmp); for(int i = 1; i <= 5; i++) change[1][i] = 1, change[0][i] = 1; int suma = 1, sumb = 1, team; while(P * suma < T || Q * sumb < T) { if(P * suma <= Q * sumb) team = 0, suma++; else team = 1, sumb++; int minn = 10000000, po; node be, aft; for(int i = 1; i <= 5; i++) { int k = change[team][i], c = a[team][i][k].val - a[team][i][k + 1].val; if(k == cnt[team][i]) continue; if(c < minn || (c == minn && a[team][i][k + 1].id < aft.id)) minn = c, po = i, be = a[team][i][k], aft = a[team][i][k + 1]; } change[team][po]++; char dui = (team == 0 ? 'A' : 'B'); printf("Substitution by %c,No.%d %s is coming up to change No.%d %s.\n", dui, aft.id, aft.name, be.id, be.name); } return 0; }
這道題到如今我仍是隻會五十分,很容易想到是一個貪心的思路,咱們直接用兩個指針表示從左邊右邊拿,就能拿五十了code
滿分的也在下面,仍是不會。。菜死了
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int A = 1e5 + 11; const int B = 1e6 + 11; const int INF = 0x3f3f3f3f; inline int read() { char c = getchar(); int x = 0, f = 1; for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1; for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); return x * f; } int n, T, x[A], a[A]; namespace sub { int maxn = -INF; inline void Main() { for(int i = 1; i <= n; i++) { int now = 0, ans = 0, l = i - 1, r = i + 1, one; while(now <= T) { if(l < 1 && r > n) break; else if(l >= 1 && r <= n && x[i] - x[l] <= x[r] - x[i]) { one = min((T - now) / ((x[i] - x[l]) * 2), a[l]); now += (x[i] - x[l]) * 2 * one, ans += one; if(one == a[l]) l--; else break; } else if(l >= 1 && r <= n && x[i] - x[l] > x[r] - x[i]) { one = min((T - now) / ((x[r] - x[i]) * 2), a[r]); now += (x[r] - x[i]) * 2 * one, ans += one; if(one == a[r]) r++; else break; } else if(l < 1 && r <= n) { one = min((T - now) / ((x[r] - x[i]) * 2), a[r]); now += (x[r] - x[i]) * 2 * one, ans += one; if(one == a[r]) r++; else break; } else if(l >= 1 && r > n) { one = min((T - now) / ((x[i] - x[l]) * 2), a[l]); now += (x[i] - x[l]) * 2 * one, ans += one; if(one == a[l]) l--; else break; } } maxn = max(maxn, ans + a[i]); } cout << maxn << '\n'; return; } } int main() { n = read(), T = read(); for(int i = 1; i <= n; i++) x[i] = read(); for(int i = 1; i <= n; i++) a[i] = read(); if(n <= 1000) return sub::Main(), 0; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 5e5 + 11; inline int read() { char c = getchar(); int x = 0, f = 1; for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1; for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); return x * f; } int s[N], T; int x[N], a[N], n; bool check(int H) { int nowh = 0, tim = 0; int lc = 0, rc = 0, l = 1, r = n + 1; for (int i = 1; i <= n; i++) if (nowh + a[i] <= H) nowh += a[i], tim += (int)(x[i] - x[1]) * a[i]; else {r = i, rc = H - nowh, tim += (int)(x[i] - x[1]) * rc; break;} if (tim <= T) return 1; for (int i = 2; i <= n; i++) { int suml = s[i - 1] - s[l - 1] - lc; int sumr = s[r - 1] - s[i - 1] + rc; tim += (x[i] - x[i - 1]) * (suml - sumr); while (r <= n && x[i] - x[l] > x[r] - x[i]) { int can = min(a[l] - lc, a[r] - rc); tim += (x[r] - x[i] - x[i] + x[l]) * can; lc += can, rc += can; if (lc >= a[l]) ++l, lc = 0; if (rc >= a[r]) ++r, rc = 0; } if (tim <= T) return 1; } return 0; } signed main() { n = read(), T = read(); T /= 2; for (int i = 1; i <= n; i++) x[i] = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; int l = 0, r = s[n], ans; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) l = mid + 1, ans = mid; else r = mid - 1; } cout << ans << '\n'; return 0; }
神仙字符串題,不會
#include<bits/stdc++.h> #define N 500010 #define ls (x << 1) #define rs (x << 1 | 1) using namespace std; typedef long long ll; struct intv{ int s, i; } a[N], b[N]; int p[N], rc[N << 2], f[N], n, m, type, anss, sum[N << 2]; ll ansf; char s[N]; bool cmp(intv a, intv b) { return a.s < b.s; } inline void updata(int x, int l, int r, int p) { if (l == r) { rc[x] = r, sum[x] = 1; return; } int mid = (l + r) >> 1; if (p <= mid) updata(ls, l, mid, p); else updata(rs, mid + 1, r, p); sum[x] = sum[ls] + sum[rs]; rc[x] = (rc[rs] == -1 ? rc[ls] : rc[rs]); } inline intv query(int x, int l, int r, int xl, int xr) { if (l == xl && r == xr) return (intv) {sum[x], rc[x]}; int mid = (l + r) >> 1; if (xr <= mid) return query(ls, l, mid, xl, xr); else if (xl > mid) return query(rs, mid + 1, r, xl, xr); else { intv ql = query(ls, l, mid, xl, mid), qr = query(rs, mid + 1, r, mid + 1, xr); return (intv) {ql.s + qr.s, qr.i == -1 ? ql.i : qr.i}; } } int main() { freopen("htstr.in", "r", stdin); freopen("htstr.out", "w", stdout); scanf("%s%d", s + 1, &type); n = strlen(s + 1); s[0] = '#'; int mx = 0, id, now = 1; for (int i = 1; i <= n; i++) { if (mx >= i) p[i] = min(mx - i, p[2 * id - i]); for (; s[i + p[i] + 1] == s[i - p[i]]; p[i]++); if (p[i] + i < mx) id = i, mx = p[i] + i; } for (int i = 1; i <= n; i++) a[i] = (intv) {i - p[i], i}; sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n << 2; i++) rc[i] = -1; for (int i = 1; i <= n; i++) { while (now <= n && a[now].s <= i) updata(1, 1, n, a[now].i), now++; if (p[i] <= 1) continue; intv qs = query(1, 1, n, i + 1, i + p[i] / 2); ansf += (ll)qs.s; if (qs.i != -1) b[++m] = (intv) {3 * i - 2 * qs.i + 1, 2 * qs.i - i}; } if (type == 1) {printf("%I64d\n", ansf + n); return 0;} sort(b + 1, b + m + 1, cmp); id = 1, mx = 0; for (int r = 1; r <= n; r++) { while (b[id].s <= r && id <= m) mx = max(mx, b[id].i), id++; if (mx < r) ++anss, mx = r; else r = mx, ++anss; } if (type == 2) printf("%d\n", anss); else printf("%I64d %d\n", ansf + n, anss); return 0; }