课上找空做了
A
原题
A. Meaning Mean
思路
贪心即可
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 110;
int n, m, k, x, y, z;
int w[N], f[N];
void solve()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
cin >> w[i];
sort(w + 1, w + n + 1);
int ans = w[1];
for (int i = 2; i <= n; i ++ )
{
ans += w[i];
ans /= 2;
}
cout << ans << "\n";
// for (int i = 1; i <= n; i ++ )
// cout << w[i] << " ";
// cout << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T -- )
{
solve();
}
}
B
原题
B. Maximize Mex
思路
想办法让其不超时即可
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010;
int n, m, k, x, y, z, ans, t;
int w[N], f[N];
void solve()
{
cin >> n >> x;
map<int, int> mm;
for (int i = 1; i <= n; i ++ )
{
cin >> m;
mm[m] ++;
}
ans = 0;
for (int i = 0; i <= n; i ++ )
{
if (mm[i] > 0)
{
mm[i] --;
if (i != i % x)
{
mm[i % x] += mm[i];
mm[i] = 0;
}
}
else if (mm[i % x] > 0)
{
mm[i % x] --;
}
else
{
break;
}
ans ++;
}
cout << ans << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T -- )
{
solve();
}
}