题意:现在需要给n个东西命名,任意连续k个不能有相同名字,给了n-k+1个连续名字的满足情况"YES"or"NO",第i个YES表示从i开始连续k个名字是互不相同的。
分析:问题在于我们如何构造出一个满足条件的n个名字,首先,我们先构造出n个互不相同的名字,首字母大写,然后看要求,如果是"NO“,令ans[i+k-1] = ans[i],这样,我们到下一个要求的时候刚开始还是两两互不相同的。知道这点,剩下就是代码实现了;
以下是代码:
复制代码
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#include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<map> #include<set> #include<stack> #include<cstring> #include<string> #include<vector> #include<unordered_set> #include<unordered_map> #include<cmath> using namespace std; #define ull unsigned long long #define ll long long #define lson l,mid,id<<1 #define rson mid+1,r,id<<1|1 typedef pair<int, int>pii; typedef pair<ll, ll>pll; typedef pair<double, double>pdd; const double eps = 1e-6; const int MAXN = 1005; const int MAXM = 5005; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const int MOD = 1000000007; const double FINF = 1e18; string s[105], ans[105]; int main() { int n, k, cnt = 0; scanf("%d%d", &n, &k); for (int i = 1; i <= n - k + 1; ++i)cin >> s[i]; for (int i = 0; i < n; ++i) { if (cnt<26)ans[i] = "A"; else ans[i] = "B"; ans[i] += (char)('a' + cnt % 26); cnt++; } int now = 1; for (int i = 1; i <= n - k + 1; ++i) { if (s[i] == "NO")ans[i+k-2] = ans[i-1]; } for (int i = 0; i < n; ++i)cout << ans[i] << " "; }
最后
以上就是唠叨冰淇淋最近收集整理的关于Codeforces 771B Bear and Different Names[构造]的全部内容,更多相关Codeforces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复