牛客小白月赛99

A

取黑色和彩色的最小即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
ll a, b, x, y;
cin >> a >> b >> x >> y;
cout << a * min(x, y) + b * y << '\n';
}
int main()
{
int Case;
cin >> Case;
while (Case--)
solve();
return 0;
}

B

贪心,尽量对半砍。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
const ll mod = 7 + 1e9;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void sol()
{
ll n;
cin >> n;
ll ans = log2(n + 1);
cout << ans << '\n';
}
signed main()
{
int t = 1;
cin >> t;
while (t--)
sol();
return 0;
}

C

先从起点出发,然后标记一下可以到达哪里。

接着从终点出发,康康这一行这一列是不是已经之前通过起点到过了。

这就是很直观的思路了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define pii pair<int, int>
const int N = 1010, mod = 998244353, INF = 0x3f3f3f3f;

char g[N][N];
int vis[N][N];

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void solve()
{
int n, m;
cin >> n >> m;
map<int, int> gx, gy;
int sx, sy, ex, ey;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> g[i][j];
if (g[i][j] == 'S')
sx = i, sy = j;
if (g[i][j] == 'E')
ex = i, ey = j;
}
}
queue<pii> q, p;
q.push({sx, sy});

while (!q.empty())
{
auto [x, y] = q.front();
q.pop();
if (vis[x][y])
continue;
vis[x][y] = 1;
for (int i = -1; i <= 1; i++)
{
gx[x + i] = gy[y + i] = 1;
}
for (int i = 0; i < 4; i++)
{
int u = x + dx[i], v = y + dy[i];
if (u < 0 || v < 0 || u == n || v == m || g[u][v] == '#' || vis[u][v])
continue;
q.push({u, v});
}
}
p.push({ex, ey});

while (!p.empty())
{
auto [x, y] = p.front();
p.pop();
// cout << x << " " << y << endl;
if (gx[x] || gy[y])
{
cout << "YES\n";
return;
}
if (vis[x][y])
continue;
vis[x][y] = 1;

for (int i = 0; i < 4; i++)
{
int u = x + dx[i], v = y + dy[i];
if (u < 0 || v < 0 || u == n || v == m || g[u][v] == '#' || vis[u][v])
continue;
p.push({u, v});
}
}
cout << "NO\n";
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T;
while (T--)
solve();

return 0;
}

D

找到质数绝对满足条件。

考察:欧拉筛+哈希。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>

using namespace std;
#define int long long
using pii = pair<int, int>;
const int N = 1e7 + 10;
int vis[N], primes[N], cnt;
signed main()
{
for (int i = 2; i < N; i++)
{
if (!vis[i])
primes[cnt++] = i;
for (int j = 0; primes[j] * i < N; j++)
{
vis[primes[j] * i] = 1;
if (i % primes[j] == 0)
break;
}
}
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
vector<int> a(n);
unordered_map<int, int> mp;
for (auto &x : a)
cin >> x, mp[x] = 1;
for (int i = 0; i <= 2e5 + 10; i++)
{
if (!mp[primes[i]])
{
cout << primes[i] << endl;
break;
}
}
}
return 0;
}

E

找到最大的m个块。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <bits/stdc++.h>
#include <set>
#include <map>
using namespace std;

#define endl "\n"
#define ll long long

void solve()
{
ll n, m;
cin >> n >> m;
vector<pair<ll, ll>> vp(n);
for (ll i = 0; i < n; i++)
cin >> vp[i].first;
for (ll i = 0; i < n; i++)
cin >> vp[i].second;
for (ll i = 0; i < n; i++)
swap(vp[i].first, vp[i].second);
sort(vp.begin(), vp.end());
vector<ll> k;
ll p = 0;
while (p < n)
{
ll rp = vp[p].first + vp[p].second;
ll sz = 1;
while (p + 1 < n && rp >= vp[p + 1].first)
{
p++;
sz++;
rp = max(rp, vp[p].first + vp[p].second);
}
p++;
k.push_back(sz);
}
sort(k.begin(), k.end());
reverse(k.begin(), k.end());
ll ans = 0;
for (ll i = 0; i < k.size() && i < m; i++)
{
ans += k[i];
}
cout << ans << endl;
}

signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
ll t;
cin >> t;
while (t--)
solve();
}