CF - 791C. Bear and Different Names - 贪心+模拟

1.题目描述:

C. Bear and Different Names
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).

A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.

You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not.

You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO".

  • The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise).
  • The string s2 describes a group of soldiers 2 through k + 1.
  • And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n.

Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.

Find and print any solution. It can be proved that there always exists at least one solution.

Input

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively.

The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise.

Output

Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.

If there are multiple valid solutions, print any of them.

Examples
input
8 3
NO NO YES YES YES NO
output
Adam Bob Bob Cpqepqwer Limak Adam Bob Adam
input
9 8
YES NO
output
R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc
input
3 2
NO NO
output
Na Na Na
Note

In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:

  • First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO".
  • Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO".
  • Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES".
  • ...,
  • Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".

2.题意概述:

有n个士兵站成一排,他们的名字分别为S1、S2......Sn,从1 到 n - k + 1分别给出从i开始连续k个士兵组成的小队伍中是否有名字相同的判断,要你构造出这样一支队伍满足所给的条件。

3.解题思路:

既然是构造,那就模拟呀。从1开始直到第一个YES的位置开始,贪心地给这k个士兵分别起不同的名字( 这样位置为0~i - 1个no的士兵都起相同的名字。因为包括他们的话,就是有重名嘛)。那么再 令j从i + 1开始往后推到n-k+1,如果第j个位置是YES代表从j到j+k个士兵又满足名字不相同,那么就给它(第j + k个士兵)赋一个新的名字,如果是NO,那就贪心地给它第j个名字(这样可以保证第j 个士兵和第j + k个士兵名字冲突,且不会影响到前j次做出的选择)。还有就是如果26个大写字母不够用就再加小写字母,但是要保证第一个字母一定是大写(这里我wa了一发,没认真读题!!!) 这里其实最多只要两个长度字符就足够,因为26^2 > 50,肯定可以完全区分地表示出所有士兵名字。

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define N 51
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
string s[N];
int ans[N];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    long _begin_time = clock();
#endif
    int n, k;
    while (~scanf("%d%d", &n, &k))
    {
        memset(ans, 0, sizeof(ans));
        for (int i = 0; i < n - k + 1; i++)
            cin >> s[i];
        int i = 0;
        while (i < n - k + 1 && s[i][0] == 'N')
            i++;
        int cnt = 1;
        for (int j = i + 1; j < i + k; j++)
        {
            ans[j] = ans[j - 1] + 1;
            cnt++;
        }
        for (int j = i + 1; j < n - k + 1; j++)
            if (s[j][0] == 'Y')
                ans[j + k - 1] = cnt++;
            else
                ans[j + k - 1] = ans[j];
        int first = 1;
        for (i = 0; i < n; i++)
            if (ans[i] + 'A' > 'Z')
            {
                char cur[3];
                cur[0] = ans[i] + 'A' - 'Z' + 'A';
                cur[1] = ans[i] + 'A' - 'Z' + 'a';
                cur[2] = '\0';
                if (first)
                {
                    first = 0;
                    printf("%s", cur);
                }
                else
                    printf(" %s", cur);
            }
            else
            {
                if (first)
                {
                    first = 0;
                    printf("%c", ans[i] + 'A');
                }
                else
                    printf(" %c", ans[i] + 'A');
            }
            puts("");
    }

#ifndef ONLINE_JUDGE
    long _end_time = clock();
    printf("time = %ld ms.", _end_time - _begin_time);
#endif
    return 0;
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值