AtCoder Beginner Contest 382 A~D
A - Daily Cookie
洛谷链接
AtCoder链接
题目
有
这些盒子的状态由长度为 @,则从左边开始的第 .,则为空。
在接下来的
求
可以保证 @。
代码
#include <bits/stdc++.h>
using namespace std;
int n, d, cnt;
string s;
int main()
{
scanf("%d %d", &n, &d);
cin >> s;
for (int i = 0; i < s.length(); i ++ )
{
if (s[i] == '@')
cnt ++;
}
cout << n - (cnt - d) << '\n';
return 0;
}
B - Daily Cookie 2
洛谷链接
AtCoder链接
题目
高桥选择 cookie 的方式和要求你找到的东西与问题 A 不同。
有
这些盒子的状态由长度为 @,那么从左边开始的第 .,则为空。
在接下来的
请判断
保证 @。
代码
#include <bits/stdc++.h>
using namespace std;
int n, d;
string s;
int main()
{
scanf("%d %d", &n, &d);
cin >> s;
for (int i = s.length() - 1; d != 0; i -- )
{
if (s[i] == '@')
{
d --;
s[i] = '.';
}
}
cout << s << '\n';
return 0;
}
C - Kaiten Sushi
洛谷链接
AtCoder链接
题目
有
现在,
对于 -1。
代码
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], x[200010], cnt, app[200010], b, w;
int main()
{
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i ++ )
{
scanf("%d", &a[i]);
if (app[a[i]] == 0)
{
x[++ cnt] = a[i];
app[a[i]] = i;
}
}
sort(x + 1, x + 1 + cnt);
for (int i = 2; i <= cnt; i ++ )
app[x[i]] = min(app[x[i]], app[x[i - 1]]);
while (m -- )
{
scanf("%d", &b);
if (b < x[1])
{
puts("-1");
continue;
}
w = upper_bound(x + 1, x + 1 + cnt, b) - x - 1;
cout << app[x[w]] << '\n';
}
return 0;
}
D - Keep Distance
洛谷链接
AtCoder链接
题目
给你整数
按词典顺序,打印所有长度为
-
- 从
2 到N 的每个整数i 的A_{i-1}+10 \le A_i 。 -
思路
这些序列最后可以很容易地按词序排序,因此我们将首先尝试简单地枚举符合要求的序列。
为便于解释,如果一个序列符合符合性序列的前缀(最初连续的几个项),我们就认为这个序列是好的。
我们将考虑如何枚举好的序列。
长度为
假设
根据这一规则枚举出好序列,问题就迎刃而解了。
由于好序列最多有
即使不评估答案的数量,我们也可以猜测符合要求的序列没有那么多,因为我们被要求打印所有的序列,并认为只要操作的数量与好序列的数量一样多,算法就会在规定的时间内完成。
代码
#include <bits/stdc++.h>
using namespace std;
int n, m, X;
vector<int> na;
int main()
{
scanf("%d %d", &n, &m);
vector<vector<int> > w = {{}};
for (int i = 1; i <= n; i ++ )
{
vector<vector<int> > v;
for (vector<int> a : w)
{
for (int x = (i == 1 ? 1 : a.back() + 10); x <= m - 10 * (n - i); x ++ )
{
na = a;
na.push_back(x);
v.push_back(na);
}
}
swap(v, w);
}
X = w.size();
cout << X << '\n';
for (int i = 0; i < X; i ++ )
{
for (int j = 0; j < n; j ++ )
cout << w[i][j] << " \n"[j == n - 1];
}
return 0;
}