AcWing 第60场周赛
AcWing 第60场周赛
https://www.acwing.com/activity/content/competition/problem_list/2048/
A. AcWing 4494. 吃饭
签到题
#include <bits/stdc++.h>
using namespace std;
int main () {
int n, m, k;
cin >> n >> m >> k;
if (n > m || n > k) cout << "No\n";
else cout << "Yes\n";
}
B. AcWing 4495. 数组操作
做法很多,一开始打算用堆做,但是没整出来。
后来写了一个二分查找第一个大于 x 的数,x是上一个最小的非零数(这样就避免了区间修改的的操作)
还是不太熟练啊...手速太慢了
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main () {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i ++) {
cin >> a[i];
}
sort (a, a + n);
int st = 0;
for (int i = 0; i < n; i ++)
if (a[i]) {
st = i;
break;
}
int x = 0;
a[n] = 0;
bool zero = false;
while (k --) {
st = upper_bound (a, a + n, x) - a;
//cout << "st=" << st << endl;
if (st == n) zero = true;
if (zero) cout << "0\n";
else cout << max(a[st] - x, 0) << endl;
x = a[st];
}
}
C. AcWing 4496. 吃水果
dp
定义f[i][j],表示放到第i个,有j个不同
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 205, mod = 998244353;
int f[N][N]; //f[i][j] 放到第i个,有j个不同
signed main () {
int n, m, k;
cin >> n >> m >> k;
//init
for (int i = 1; i <= n; i ++) f[i][0] = m; //所有同学都一样
for (int i = 2; i <= n; i ++)
for (int j = 1; j <= k; j ++) {
f[i][j] = f[i-1][j]; //一样
f[i][j] = (f[i][j] + f[i-1][j-1] * (m-1) % mod) % mod; //不一样
}
cout << f[n][k] << endl;
}
//dp