视频题解。
这场题目质量还可以,只是E太水了。。
AB贪心+模拟就不用多说了,C其实是个标准的三分,但要注意一下如果有多个极值点的情况要选最小的一个,在代码实践中加个=就行。D题利用好权值范围不超过60这个性质,维护最优集合,可以证明这个最优集合最大为60,然后就随便做的,但注意要判断相等的情况(一开始没考虑这里fst了)。E题水题,通过样例可以发现构造思路,证明也很容易。
A. Berland Poker
/*
* Author: heyuhhh
* Created Time: 2020/5/28 22:36:35
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
void run() {
int n, m, k; cin >> n >> m >> k;
int has = n / k;
if (m <= has) {
cout << m << '
';
} else {
int ans = max(0, has - (m - has + k - 2) / (k - 1));
cout << ans << '
';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}
B. New Theatre Square
/*
* Author: heyuhhh
* Created Time: 2020/5/28 22:41:15
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
void run() {
int n, m, x, y;
cin >> n >> m >> x >> y;
y = min(y, 2 * x);
vector <string> s(n);
ll ans = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 1; j < m; j++) {
if (s[i][j - 1] == '.' && s[i][j] == '.') {
ans += y;
s[i][j - 1] = s[i][j] = '*';
++j;
}
}
for (int j = 0; j < m; j++) {
if (s[i][j] == '.') ans += x;
}
}
cout << ans << '
';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}
C. Mixing Water
/*
* Author: heyuhhh
* Created Time: 2020/5/28 22:56:00
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
const double eps = 1e-6;
void run() {
int h, c, t; cin >> h >> c >> t;
if (h + c >= 2 * t) {
cout << 2 << '
';
return;
}
auto f = [&] (ll x, ll y) {
return fabs((double)t - 1.0 * (x * h + y * c) / (x + y));
};
ll l = 0, r = INF, lmid, rmid;
while (l < r) {
lmid = l + ((r - l) / 3);
rmid = r - ((r - l) / 3);
if (f(lmid + 1, lmid) <= f(rmid + 1, rmid)) {
r = rmid - 1;
} else {
l = lmid + 1;
}
}
ll ans = 2 * l + 1;
//if (l > 10000000) {
//ans = ll(1.0 * (h - t) / (2 * t - h - c) + 0.5);
//ans = 2ll * ans + 1;
//}
cout << ans << '
';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T; while(T--)
run();
return 0;
}
D. Yet Another Yet Another Task
/*
* Author: heyuhhh
* Created Time: 2020/5/28 23:50:13
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
int a[N];
int f[N][21];
int n;
void Get_st(){
for(int j=1;j<=20;j++)
for(int i=1;i<=n;i++)
if(i+(1<<(j-1))<=n) f[i][j]=max(f[i][j-1],f[i+(1<<(j-1))][j-1]);
}
int Get_max(int l,int r){
int k=0;
while(1<<(k+1)<=r-l+1) k++;
return max(f[l][k],f[r-(1<<k)+1][k]);
}
void run() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[i][0] = a[i];
}
Get_st();
set <pii> s;
s.insert(MP(0, 0));
int ans = -INF;
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += a[i];
for (auto it : s) {
int res = sum - it.fi - Get_max(it.se + 1, i);
ans = max(ans, res);
}
auto it = s.lower_bound(MP(sum, 0));
if (it != s.end() && it -> fi == sum) {
s.erase(it);
}
s.insert(MP(sum, i));
if (sz(s) > 60) {
auto it = s.end(); --it;
s.erase(it);
}
}
cout << ans << '
';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}
E. Modular Stability
/*
* Author: heyuhhh
* Created Time: 2020/5/29 0:15:24
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5, MOD = 998244353;
int qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
void run() {
int n, k; cin >> n >> k;
if (n < k) {
cout << 0 << '
';
return;
}
vector <int> fac(n + 1), inv(n + 1);
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
inv[n] = qpow(fac[n], MOD - 2);
for (int i = n - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
auto C = [&] (int n, int m) {
return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
};
int ans = 0;
for (int i = 1; i <= n; i++) {
int cnt = n / i - 1;
if (1 + cnt >= k) {
ans = (ans + C(cnt, k - 1)) % MOD;
}
}
cout << ans << '
';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}