zoukankan      html  css  js  c++  java
  • 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 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 ofk 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".

    题意:给出需要输出的字符个数,给出其每个区间范围,要我们构造符合要求的字符串输出,(NO表示区间内有相同字符串,YES表示都不相同)

    解法:我们假设  12345

                             23456,如果区间为NO,最好的做法是将5改成1,这样不会影响到下一个区间的判断

                           12341

                             23416

    我们打一个有大写字母开头的A-Z,小写字母a-z结尾的表,遇见NO就将区间最后一个字符串改成区间第一个

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int ans[55];
     4 string name[1005];
     5 int n,m;
     6 string s;
     7 void cmd()
     8 {
     9     int cot=0;
    10     for(int i=0; i<26; i++)
    11     {
    12         for(int j=0; j<26; j++)
    13         {
    14             string s="";
    15             s+='A'+i;
    16             s+='a'+j;
    17             name[cot++]=s;
    18         }
    19     }
    20 }
    21 int main()
    22 {
    23     cmd();
    24     cin>>n>>m;
    25     for(int i=0; i<=n; i++)
    26     {
    27         ans[i]=i;
    28     }
    29     for(int i=0; i<n-m+1; i++)
    30     {
    31         cin>>s;
    32         if(s=="NO")
    33         {
    34             ans[i+m-1]=ans[i];
    35         }
    36     }
    37     cout<<name[0];
    38     for(int i=1; i<n; i++) cout<<" "<<name[ans[i]];
    39     cout<<endl;
    40     return 0;
    41 }
  • 相关阅读:
    一次Zookeeper 扩展之殇
    宜信敏捷数据中台建设实践|分享实录
    初学Docker容器网络不得不看的学习笔记
    Codeforce-CodeCraft-20 (Div. 2)-B. String Modification (找规律+模拟)
    Codeforce-CodeCraft-20 (Div. 2)-A. Grade Allocation
    Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)
    Codeforce-Ozon Tech Challenge 2020-B. Kuroni and Simple Strings(贪心)
    Codeforce-Ozon Tech Challenge 2020-A. Kuroni and the Gifts
    Codeforces Round #509 (Div. 2) A. Heist 贪心
    CodeForces
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6666888.html
Copyright © 2011-2022 走看看