I am a slow walker,but I never walk backwards. Abraham Lincoln

GeekZRF

Codeforces 791C. Bear and Different Names 模拟构造

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".

题目链接:http://codeforces.com/contest/791/problem/C

题意:有n个人,按照每k个人进行分组:1~k,2~k+1,3~k+2...,n-k+1~n。如果本组内有名字相同的人,这一组表示为"NO";否者表示为"YES"。现在要求你构造n个人的名字,名字由一个长度不超过10的字母字符串组成,并且首字母大写。

思路:初始化每个人的名字为ans[i]=i。那么每个人的名字均不相同,但是有一些分组的人的名字是相同的,即为"NO"的情况。所以要更改这一组的一些人的名字,但是不能影响上一组和下一组。本组的前k-1个人与上一组的人重合,本组的后k-1个人与下一组重合。所以更改为本组的第一个人的名字和本组的第k个人的名字相同不会对上一组和下一组造成影响。

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<vector>
 8 using namespace std;
 9 typedef long long ll;
10 const int MAXN=2e5+100,INF=0x3f3f3f3f,MOD=1e9+7;
11 char s[100][5];
12 string sign[60]= {"Aa","Ab","Ac","Ad","Ae","Af","Ag","Ah","Ai","Aj",
13                   "Ak","Al","Am","An","Ao","Ap","Aq","Ar","As","At",
14                   "Au","Av","Aw","Ax","Ay","Az","Ba","Bb","Bc","Bd",
15                   "Be","Bf","Bg","Bh","Bi","Bj","Bk","Bl","Bm","Bn",
16                   "Bo","Bp","Bq","Br","Bs","Bt","Bu","Bv","Bw","Bx",
17                   "By","Bz","Ca","Cb","Cc","Cd","Ce","Cf","Cg","Ch"
18                  };
19 int ans[100];
20 int main()
21 {
22     int n,k;
23     scanf("%d%d",&n,&k);
24     int x=n-k;
25     for(int i=0; i<=x; i++) scanf("%s",s[i]);
26     for(int i=0; i<n; i++) ans[i]=i;
27     for(int i=0; i<=x; i++)
28     {
29         if(s[i][0]=='Y') continue;
30         ans[i+k-1]=ans[i];
31     }
32     for(int i=0; i<n; i++)
33         cout<<sign[ans[i]]<<" ";
34     cout<<endl;
35     return 0;
36 }
View Code

 

posted on 2017-03-19 13:35  GeekZRF  阅读(306)  评论(0编辑  收藏  举报

导航