A题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const int MAXN = 100010;
int main(void) {
int n;
cin >> n;
vector<int> st;
for (int i = 0; i < n; ++ i) {
int x;
cin >> x;
if (!st.empty() && (st.back() + x) % 2 == 1) st.pop_back();
else st.push_back(x);
}
cout << st.size() << endl;
return 0;
}
===================================
B题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const int MAXN = 100010;
bool can[30][30];
int dp[100010][30];
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < 26; ++ i) for (int j = 0; j < 26; ++ j) can[i][j] = true;
int m;
cin >> m;
for (int i = 0; i < m; ++ i) {
string t;
cin >> t;
can[t[0]-'a'][t[1]-'a'] = false;
can[t[1]-'a'][t[0]-'a'] = false;
}
memset(dp, 0x3f, sizeof(dp));
vector<int> lst(26, 0);
lst[s[0] - 'a'] = 1;
dp[1][s[0] - 'a'] = 0;
for (int i = 2; i <= n; ++ i) {
for (int j = 0; j < 26; ++ j) {
dp[i][j] = dp[i - 1][j] + 1;
}
int ch = s[i - 1] - 'a';
for (int j = 0; j < 26; ++ j) if (can[ch][j] && lst[j]) {
dp[i][ch] = min(dp[i][ch], dp[lst[j]][j] + i - lst[j] - 1);
}
dp[i][ch] = min(dp[i][ch], i - 1);
lst[ch] = i;
}
int ans = n;
for (int i = 0; i < 26; ++ i) ans = min(ans, dp[n][i]);
cout << ans << endl;
return 0;
}
===================== C题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define fst first
#define snd second
const int MAXN = 100010;
const ll inf = 1000000000000LL;
vector<pii> ow[10010];
//priority_queue<pii, vector<pii>, greater<pii>> pq[110];
ll e[10010];
int lst[10010];
int main(void) {
map<int, int> sid;
int n, m, K;
cin >> n >> m >> K;
//for (int i = 1; i <= m; ++ i) e[i].fst = inf;
vector<ll> s(n), t(n), p(n);
for (int i = 0; i < n; ++ i) {
lst[i] = 0;
cin >> s[i] >> t[i] >> p[i];
sid[s[i]] = i;
e[i] = t[i] + K;
for (int j = 0; j < p[i]; ++ j) {
ll o, w;
cin >> o >> w;
ow[i].emplace_back(pii(o, w));
/*
if (j == 0 && (t[i] + K < e[o].fst || (t[i] + K == e[o].fst && e[o].snd > s[i]))) {
e[o].fst = t[i] + K;
e[o].snd = s[i];
}
*/
}
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
for (int i = 0; i < n; ++ i) pq.push(pii(e[i], s[i]));
vector<ll> curt(m + 1, 0);
vector<ll> ans(n);
while ( !pq.empty() ) {
ll ee = inf, eid = 0;
/*
for (int i = 0; i < n; ++ i) if (lst[i] < p[i]) {
if (e[i] < ee || (e[i] == ee && s[eid] > s[i])) {
eid = i;
ee = e[i];
}
}
*/
/*
for (int i = 1; i <= m; ++ i) {
if (!pq[i].empty() && pq[i].top().fst < ee) {
ee = pq[i].top().fst;
eid = i;
}
}
*/
ee = pq.top().fst, eid = sid[pq.top().snd];
pq.pop();
//if (ee == inf) break;
int id = ow[eid][lst[eid]].fst;
//pii cur = pq[eid].top(); pq[eid].pop();
//ll time = cur.fst;
//ll id = sid[cur.snd];
//cerr << eid << ' ' << id << ' ' << e[eid] << endl;
if (lst[eid] >= (ll)ow[eid].size() - 1) {
ans[eid] = max(e[eid], curt[id]) + ow[eid][lst[eid]].snd;
e[eid] = ans[eid];
curt[id] = ans[eid];
} else {
//ll nid = ow[eid][lst[eid] + 1].fst;
ll ntime = max(e[eid], curt[id]) + ow[eid][lst[eid]].snd + K;
curt[id] = ntime - K;
e[eid] = ntime;
pq.push(pii(ntime, s[eid]));
}
++ lst[eid];
}
for (int i = 0; i < n; ++ i) cout << ans[i] << endl;
return 0;
}
嗯,这题要记录几个东西,一个是每台机器available的时间点,然后我搞一个priority queue,里面保存的是每个人下一步要去的office,然后每次从queue里面取出一个最早到达下一个office的人,然后走到下一个office,压到queue里面。