C. Bear and Different Names

题目连接:

http://codeforces.com/contest/791/problem/C

Description

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.

Sample Input

8 3

NO NO YES YES YES NO

Sample Output

Adam Bob Bob Cpqepqwer Limak Adam Bob Adam

Hint

题意

你需要构造n个名字,满足n-k+1个要求。

如果第i个要求是YES的话,那么要求[i,i+k-1]的名字都不相同。

如果第i个要求是NO的话,那么要求[i,i+k-1]的名字至少有两个是相同的。

题解:

如果是YES的话,那么就让[i,i+k-1]里面的点相互连边,连边表示不能取相同的名字。

然后我们就开始贪心构造就好了,在满足不和相连的点取相同名字的前提下,取离自己最近的人的名字就好了。

代码

#include<bits/stdc++.h>
using namespace std; int n,k;
int flag[55];
int fa[55];
int ans[55];
int tot = 0;
int mp[55][55];
string getid(int x){
if(x<26){
string t;
t+=('A'+x);
return t;
}else{
string t = "A";
t+=(x-25+'a');
return t;
}
}
int vis[55];
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n-k+1;i++){
string op;
cin>>op;
if(op[0]=='Y'){
for(int j=i;j<i+k;j++){
for(int p=j+1;p<i+k;p++){
mp[j][p]=1;
mp[p][j]=1;
}
}
}
}
for(int i=1;i<=n;i++){
int Flag = 0;
memset(vis,0,sizeof(vis));
for(int j=i-1;j>=1;j--){
if(mp[i][j]==1){
vis[ans[j]]=1;
}
}
for(int j=i-1;j>=1;j--){
if(vis[ans[j]]==0){
ans[i]=ans[j];
Flag = 1;
break;
}
}
if(Flag==0){
for(int j=0;j<=50;j++){
if(vis[j]==0){
ans[i]=j;
break;
}
}
}
}
for(int i=1;i<=n;i++){
cout<<getid(ans[i])<<" ";
}
cout<<endl;
}

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心的更多相关文章

  1. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  2. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  3. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

  4. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)

    A 模拟 B 发现对于每个连通块,只有为完全图才成立,然后就dfs C 构造 想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难.. 考虑对于顺序枚举每一个NO/YES, ...

  5. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)A B C 水 并查集 思路

    A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. 【构造】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) A. Bear and Different Names

    如果某个位置i是Y,直接直到i+m-1为止填上新的数字. 如果是N,直接把a[i+m-1]填和a[i]相同即可,这样不影响其他段的答案. 当然如果前面没有过Y的话,都填上0就行了. #include& ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) E

    Description Bear Limak prepares problems for a programming competition. Of course, it would be unpro ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) D

    Description A tree is an undirected connected graph without cycles. The distance between two vertice ...

  9. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

    Description In the army, it isn't easy to form a group of soldiers that will be effective on the bat ...

随机推荐

  1. js导出excel表格中较长数字串会变成科学计数法问题

    在做项目中,遇到导出excel表格时,银行账户号数字过长,导出的数字串变为计数法形式,如下图: 网上搜到解决方法,粘贴到这以供学习.不断更新. 原博地址:http://www.cnblogs.com/ ...

  2. centos下httpd-2.4的编译安装

    httpd-2.4编译安装     依赖于更高版本的apr和apr-util      apr 全称  apache portable runtime 首先停用低版本的httpd服务 service ...

  3. 自定义el标签

    编写java代码 package com.ycjk.common; public class FormatJSEltarg { public static String format(String s ...

  4. spring事物深入了解

    1.问题 1.以前对事物的了解只是停留在声明式事物,配置xml,或使用注解,事物的传播行为也只用过REQUIRED和SUPPORTS,可以说对事物的了解很模糊. 2.直到在开发中遇到问题.. 问题的描 ...

  5. 红包外挂史及AccessibilityService分析与防御

    最近在做一个有趣的外挂的小玩意,前提我们要了解一个重要的类AccessibilityService 转载请注明出处:https://lizhaoxuan.github.io 前言 提起Accessib ...

  6. php高级工程师面试题,行不行对照看下自己的实力

    在网上看到一些高级php 的面试题目.. 最近接连面试了几家公司,有些重要问题记录一下,督促自己学习提高,同时希望给朋友们一些帮助.内容很多,一点点完善,一步步学习..有些是面试被问,有些是招聘要求, ...

  7. java多线程快速入门(六)

    多线程应用实例(批量发送短信) 1.创建实体类 package com.cppdy; public class UserEntity { private int id; private String ...

  8. LeetCode(35):搜索插入位置

    Easy! 题目描述: 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1 ...

  9. uva12436 回头再做一次

    线段树维护等差数列,结点维护首项+公差即可 #include <cstdio> #include <cstring> #include <algorithm> us ...

  10. poj 1679 判断MST是不是唯一的 (次小生成树)

    判断MST是不是唯一的 如果是唯一的 就输出最小的权值和 如果不是唯一的 就输出Not Unique! 次小生成树就是第二小生成树  如果次小生成树的权值和MST相等  那么MST就不是唯一的 法一: ...