Codeforces Round #667 (Div. 3)
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 long long ll;
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 main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> m;
n = abs(n - m);
if(!n) cout << 0 << '\n';
else cout << ((n - 1) / 10 + 1) << '\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 long long ll;
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 main() {
IOS;
for (cin >> _; _; --_) {
ll a, b, x, y, n; cin >> a >> b >> x >> y >> n;
ll c = min(n, a - x);
ll a1 = a - c, b1 = max(b - n + c, y);
c = min(n, b - y);
ll b2 = b - c, a2 = max(a - n + c, x);
if (a1 * b1 < a2 * b2) cout << a1 * b1 << '\n';
else cout << b2 * a2 << '\n';
}
return 0;
}
C
这里是薄弱, 花太多时间了
#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 long long ll;
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 x, y, z, ans, xd, xa;
void check(int d) {
int c = z / d, e = x % d;
if (!e) e = d;
if (c >= n) return;
if ((y - e) / d >= n)
e = y - (n - 1) * d;
if (e + (n - 1) * d < ans) {
ans = (n - 1) * d + e;
xa = e, xd = d;
}
}
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> x >> y;
z = y - x; ans = 1e9;
rep (i, 1, z / i)
if (z % i == 0) {
check(i);
if (i * i != z) check(z / i);
}
xa -= xd;
rep (i, 1, n) cout << xa + i * xd << ' ';
cout << endl;
}
return 0;
}
D
#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 long long ll;
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[20], tot;
ll s[20] = {1};
int main() {
IOS;
rep (i, 1, 18) s[i] = s[i - 1] * 10;
for (cin >> _; _; --_) {
ll n, ans = 0; cin >> n >> m; k = tot = 0;
while (n) {
a[tot++] = n % 10; n /= 10;
k += a[tot - 1];
}
for (int i = 0; i < tot && k > m; ++i) {
if (a[i]) {
k -= a[i]; ans += s[i] * (10 - a[i]);
for (int j = i + 1; ; ++j) {
if (j == tot) { a[tot++] = 1; break; }
else if (a[j] == 9) a[j] = 0, k -= 9;
else { ++a[j], ++k; break; }
}
}
}
cout << ans << endl;
}
return 0;
}
E
a[i] 表示从(排好序) 第 i 个点放木板可接住的点的数量, b[i] 表示 在 i~n max(a[i]), 枚举就行
#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 long long ll;
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;
PII p[N];
int a[N], b[N], c[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> k; m = b[n + 1] = 0;
rep (i, 1, n) cin >> p[i].fi;
rep (i, 1, n) cin >> p[i].se;
sort(p + 1, p + 1 + n);
int l = 1, r = 2;
for ( ; r <= n; ++r)
while (p[r].fi - p[l].fi > k) a[l] = r - l, c[l++] = r;
while (l < r) a[l] = r - l, c[l++] = r;
per (i, n, 1) b[i] = max(b[i + 1], a[i]);
rep (i, 1, n) m = max(m, a[i] + b[c[i]]);
cout << m << endl;
}
return 0;
}
F
dp
#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 long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 2e2 + 5;
int n, m, _, k;
int f[N][N][N];
char s[N], t[5];
int main() {
IOS; cin >> n >> k >> s + 1 >> t + 1;
memset(f, -0x3f, sizeof f); f[0][0][0] = 0;
rep (i, 1, n)
rep (j, 0, i)
rep (x, 0, min(i, k))
rep (ch, 'a', 'z') {
int nx = (ch == s[i] ? x : x + 1);
int nj = (ch == t[1] ? j + 1 : j);
f[i][nj][nx] = max(f[i][nj][nx], f[i - 1][j][x] + (ch == t[2] ? j : 0));
}
int ans = 0;
rep (i, 0, n)
rep (j, 0, k) ans = max(ans, f[n][i][j]);
cout << ans;
return 0;
}