题意:现在需要给n个东西命名,任意连续k个不能有相同名字,给了n-k+1个连续名字的满足情况"YES"or"NO",第i个YES表示从i开始连续k个名字是互不相同的。
分析:问题在于我们如何构造出一个满足条件的n个名字,首先,我们先构造出n个互不相同的名字,首字母大写,然后看要求,如果是"NO“,令ans[i+k-1] = ans[i],这样,我们到下一个要求的时候刚开始还是两两互不相同的。知道这点,剩下就是代码实现了;
以下是代码:
#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] << " ";
}