AtCoder Beginner Contest 332
A
思路
累加费用,如果总价小于 \(S\) 则加上运费 \(K\)
Code
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
#define endl '\n'
const int mod = 998244353;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
void solve()
{
int n, s, k;
cin >> n >> s >> k;
int ans = 0;
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
ans += x * y;
}
if (ans < s)
ans += k;
cout << ans;
}
int main()
{
cin.tie(0)->ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
B
思路
根据题意模拟
执行 \(K\) 次以下操作:
- 如果玻璃杯是满的,清空玻璃杯
- 否则,如果马克杯是空的,装满马克杯
- 否则,将马克杯里的水倒进玻璃杯,直到马克杯为空或者玻璃杯满了
Code
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
#define endl '\n'
const int mod = 998244353;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
void solve()
{
int k, g, m;
cin >> k >> g >> m;
int gg = 0, mm = 0;
while (k--)
{
if (gg == g)
gg = 0;
else if (mm == 0)
mm = m;
else
{
int t = min(g - gg, mm);
mm -= t;
gg += t;
}
}
cout << gg << ' ' << mm;
}
int main()
{
cin.tie(0)->ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
C
思路
根据题意模拟
出现 \(0\) 重置衣服的数量,出现 \(1\) 优先用纯色,没有衣服可穿就返回 \(false\)
Code
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
#define endl '\n'
const int mod = 998244353;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
int n, m;
string s;
bool check(int x)
{
int a = m, b = x;
for (int i = 0; i < n; i++)
{
if (s[i] == '0')
a = m, b = x;
else if (s[i] == '1')
{
if (a)
a--;
else if (b)
b--;
else
return false;
}
else
{
if (b)
b--;
else
return false;
}
}
return true;
}
void solve()
{
cin >> n >> m >> s;
for (int i = 0; i <= 1000; i++)
{
if (check(i))
{
cout << i;
return;
}
}
}
int main()
{
cin.tie(0)->ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
D
思路
\(BFS\) 搜索
用嵌套 \(STL\) 进行操作简单方便
Code
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
#define endl '\n'
const int mod = 998244353;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
void solve()
{
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
vector<vector<int>> b(n, vector<int>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> b[i][j];
int ans = INF;
map<vector<vector<int>>, int> vis;
queue<pair<vector<vector<int>>, int>> q;
q.push({a, 0});
while (!q.empty())
{
vector<vector<int>> now = q.front().first;
int cnt = q.front().second;
q.pop();
if (now == b)
{
ans = min(ans, cnt);
continue;
}
for (int i = 0; i < n - 1; i++)
{
swap(now[i], now[i + 1]);
if (vis[now] == 0)
{
vis[now] = 1;
q.push({now, cnt + 1});
}
swap(now[i], now[i + 1]);
}
for (int j = 0; j < m - 1; j++)
{
for (int i = 0; i < n; i++)
swap(now[i][j], now[i][j + 1]);
if (vis[now] == 0)
{
vis[now] = 1;
q.push({now, cnt + 1});
}
for (int i = 0; i < n; i++)
swap(now[i][j], now[i][j + 1]);
}
}
cout << (ans != INF ? ans : -1);
}
int main()
{
cin.tie(0)->ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
E
思路
待补
Code
1
AtCoder Beginner Contest 332
http://xiaowhang.github.io/archives/2658756992/