Educational Codeforces Round 95 (Rated for Div. 2)
A
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[N];
int main() {
IOS;
for (cin >> _; _; --_) {
ll n, m, k; cin >> n >> m >> k;
cout << ((k * (m + 1) - 2) / (n - 1) + 1 + k) << '\n';
}
return 0;
}
B
贪心
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[N], b[N], s[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n; VI v;
rep (i, 1, n) cin >> a[i], s[i] = s[i - 1] + a[i];
rep (i, 1, n) {
cin >> b[i];
if (!b[i]) v.pb(a[i]);
}
sort(all(v));
rep (i, 1, n)
if (!b[i]) cout << v.back() << ' ', v.pop_back();
else cout << a[i] << ' ';
cout << '\n';
}
return 0;
}
C
dp, 三位, 第一维是第 i 个怪兽, j 你的朋友杀了几只怪取(1, 2), k 你杀了几只怪(可取 0, 1, 2)
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 2e5 + 5;
int n, m, _, k;
int a[N], f[N][3][3];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n;
rep (i, 0, n) memset(f[i], 0x3f, sizeof f[i]);
f[0][2][2] = 0;
rep (i, 1, n) {
cin >> a[i];
f[i][1][0] = min(f[i - 1][1][1], min(f[i - 1][1][2], f[i - 1][2][2])) + a[i];
f[i][1][1] = f[i - 1][1][0];
f[i][1][2] = f[i - 1][1][1];
f[i][2][0] = f[i - 1][1][0] + a[i];
f[i][2][1] = f[i - 1][2][0];
f[i][2][2] = f[i - 1][2][1];
}
int ans = 1e9;
rep (i, 1, 2) rep (j, 0, 2) ans = min(f[n][i][j], ans);
cout << ans << '\n';
}
return 0;
}
D
stl的应用, 模拟就完事
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 2e5 + 5;
int n, m, _, k;
ll s = 0;
set<int> st;
map<int, int> sum;
void check(int x) {
if (sum[x] == 0) sum.erase(x);
}
void insert(int x) {
if (st.empty()) { st.insert(x); return; }
auto it = st.insert(x).fi;
auto be = it, af = it;
if (it != st.begin()) --be;
if (af != --st.end()) ++af;
//cout << *be << ' ' << x << ' ' << *af << '\n';
if (af == it) ++sum[x - *be], s += x - *be;
else if (it == be) ++sum[*af - x], s += *af - x;
else ++sum[x - *be], ++sum[*af - x], --sum[*af - *be], check(*af - *be);
}
void delet(int x) {
if (st.size() == 1) { st.clear(); return; }
auto it = st.find(x);
auto be = it, af = it;
if (it != st.begin()) --be;
if (af != --st.end()) ++af;
//cout << *be << ' ' << x << ' ' << *af << '\n';
if (af == it) --sum[x - *be], s -= x - *be, check(x - *be);
else if (be == it) --sum[*af - x], s -= *af - x, check(*af - x);
else --sum[x - *be], --sum[*af - x], ++sum[*af - *be], check(x - *be), check(*af - x);
st.erase(it);
}
int main() {
IOS; cin >> n >> m;
rep (i, 1, n) cin >> k, insert(k);
if (!sum.empty())cout << s - (*sum.rbegin()).fi << '\n';
else cout << s << '\n';
rep (i, 1, m) {
cin >> _ >> k;
if (_) insert(k);
else delet(k);
if (!sum.empty()) cout << s - (*sum.rbegin()).fi << '\n';
else cout << s << '\n';
}
return 0;
}