day14(模拟赛)总结
最后一场模拟赛挂了。
tm不知道啥时候改样例了又没看见。
400 -> 300
Fall into the dark side了。
预期:100 + 100 + 100 + 50 + 50
实际:100 + 0 + 100 + 50 + 50
T1
签到题。
只要 Yes,否则输出 No。
由于
况且题目都提醒我们了。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int kMaxN = 1e5 + 5;
int t, a, b, s;
void solve() {
cin >> a >> b >> s;
a = abs(a), b = abs(b);
cout << (s < (a + b) || (s - (a + b)) % 2 ? "No\n" : "Yes\n");
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (cin >> t; t; t--)
solve();
return 0;
}
B
水题写成了一滩烂泥。
首先,当
当
求最小值时,高位越小越好,所以填数时先假设这一位填
否则差多少填多少。
求最大值时,高位越大越好,所以填数时先假设这一位和后面全填
否则比
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int kMaxN = 1e5 + 5;
int t, m, s, type;
void get_ans(int type) {
int sum = 0;
for (int i = 1; i <= m; i++) {
int x = (type ? max(int(i == 1), s - (sum + 9 * (m - i))) : min(9, s - sum));
sum += x;
cout << x;
}
cout << " ";
}
void solve() {
cin >> m >> s >> type;
if (!s && m == 1) {
cout << (type == 3 ? "0 0\n" : "0\n");
return;
}
if (!s || s > 9 * m) {
cout << (type == 3 ? "-1 -1\n" : "-1\n");
return;
}
if (type != 2)
get_ans(1);
if (type != 1)
get_ans(0);
cout << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (cin >> t; t; t--)
solve();
return 0;
}
然而最大最小值全错了。
问题集中在第
int x = (type ? max(int(i != 1), s - (sum + 9 * (m - i))) : min(9, s - (sum + m - i)));
最小值错哪了?
写错了。
== -> !=
最大值错哪了?
最小值考虑到的
100 -> 0,寄。
C
什么神机,比颠佬还颠。
首先,我们需要一个数组
显然,编号为
所以操作次数是
然后只需要将
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int kMaxN = 1e5 + 5;
ll n, m, k, a[kMaxN], mp[kMaxN];
void solve() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]] = i;
}
ll ans = 0, x;
for (int i = 1; i <= m; i++) {
cin >> x;
ans += (mp[x] - 1) / k + 1;
if (mp[x] != 1) {
swap(a[mp[x]], a[mp[x] - 1]);
mp[x]--;
mp[a[mp[x] + 1]]++;
}
}
cout << ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
D
暴力50遗憾离场。
50pts
这个不多说,暴力搜索,三种情况:不选、选原数、选阶乘。
注意只有原数
时间复杂度
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k, s, a[30], ans, f[20];
inline void dfs(ll x, ll y, ll sum) {
if (sum > s)
return;
if (x > n) {
ans += (sum == s);
return;
}
if (a[x] <= 18 && y < k)
dfs(x + 1, y + 1, sum + f[a[x]]);
dfs(x + 1, y, sum + a[x]);
dfs(x + 1, y, sum);
}
inline void solve() {
cin >> n >> k >> s;
for (int i = 1; i <= n; i++)
cin >> a[i];
sort(a + 1, a + n + 1, greater<ll>());
f[1] = 1;
for (int i = 2; i <= 18; i++)
f[i] = f[i - 1] * i;
dfs(1, 0, 0);
cout << ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
100pts
据说是折半搜,我还没写出来。
E
还得是暴力,两题带走100pts。
50pts
每一次加数都求一遍LIS即可,时间复杂度略低于
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int kMaxN = 5e4 + 5;
int n, p[kMaxN], k[kMaxN], f[kMaxN], lis[kMaxN], len;
inline void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
for (int i = 1; i <= n; i++)
cin >> k[i];
for (int i = 1; i <= n; i++) {
f[k[i]] = 1;
len = 0;
for (int j = 1; j <= n; j++) {
if (f[j]) {
int pos = lower_bound(lis + 1, lis + len + 1, p[j]) - lis;
if (pos > len)
len++;
lis[pos] = p[j];
}
}
cout << len << " ";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}