(CodeForces - 771B)Bear and Different Names

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

题意:给你n个数,有一个小窗口长度为k,小窗口从1开始向右移动,如果输入YES,则这个小窗口内的所有名字不能相同,否则名字可以相同。

思路:贪心,你会发现小窗口第一次停在左侧为1的位置,并且前k-1个数各不相同,其实你输出了k-1个数,剩下n-(k-1)的就是你输入yes no的数量,因为他一共需要输入n-k+1个yes或no。
先设定下输出,如果num的值<91(Z的ascii码为90) 输出他就行,否则就输出字符串A+(num+6)(因为a的ascii码为97 不满足条件num肯定>90,所以最小的值就是91+6=97了,避免输出其他非字母字符) 你会问这样可以吗 你算下大写的字符有26个 小写的字母有26个 一共52个,题目给的数据为50个 刚刚好。
前k-1个数,先设定一个初始值num=65(A的ascii码为65,转化为字符串就是A了),然后num++直接输出前k-1个
输入一个YES,说明不能有重复的,所以跟前k-1个数一样num++输出。
输入一个NO,让这个值跟小窗口的第一个值相等,因为如果让其他值跟他相等就不能保证下一次输入YES,不一定是YES了,因为小窗口移动下一个,自然地就把上一步的第一个去除。 讲到这里就很明白了!!!!

AC代码:

#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int mmax=1e6+10;
string getnum(ll num)
{
	string s;
	if(num<91)
		s.push_back(num);
	else
	{
		s.push_back('A');
		s.push_back(num+6);
	}
	return s;
}
int main()
{
	ll n,k;
	while(cin>>n>>k)
	{
		ll num=65;
		string s1[100],op;
		for(int i=0;i<n;i++)
		{
			if(i<k-1)
			{
				s1[i]=getnum(num);
				num++;
				cout<<s1[i]<<" ";
			}
			else
			{
				cin>>op;
				if(op=="YES")
				{
					s1[i]=getnum(num);
					num++;
					cout<<s1[i]<<" ";
				}
				else
				{
					s1[i]=s1[i-k+1];
					cout<<s1[i]<<" ";
				}
			}
		}
		cout<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaHua_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值