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.
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.
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.
8 3
NO NO YES YES YES NO
Adam Bob Bob Cpqepqwer Limak Adam Bob Adam
9 8
YES NO
R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc
3 2
NO NO
Na Na Na
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就将区间最后一个字符串改成区间第一个
#include<bits/stdc++.h>
using namespace std;
int ans[];
string name[];
int n,m;
string s;
void cmd()
{
int cot=;
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
string s="";
s+='A'+i;
s+='a'+j;
name[cot++]=s;
}
}
}
int main()
{
cmd();
cin>>n>>m;
for(int i=; i<=n; i++)
{
ans[i]=i;
}
for(int i=; i<n-m+; i++)
{
cin>>s;
if(s=="NO")
{
ans[i+m-]=ans[i];
}
}
cout<<name[];
for(int i=; i<n; i++) cout<<" "<<name[ans[i]];
cout<<endl;
return ;
}
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C的更多相关文章
- 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 ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心
C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...
- 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 ...
- 【树形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的整数倍,还要加上多少. 于是, ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)
A 模拟 B 发现对于每个连通块,只有为完全图才成立,然后就dfs C 构造 想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难.. 考虑对于顺序枚举每一个NO/YES, ...
- 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 ...
- 【构造】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& ...
- 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 ...
- 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 ...
随机推荐
- 浅谈JavaScript的函数表达式(闭包)
前文已经简单的介绍了函数的闭包.函数的闭包就是有权访问另一个函数作用域的函数,也就是函数内部又定义了一个函数. var Super=function(num){ var count=num; retu ...
- 在VC中动态加载ODBC的方法
在使用VC.VB.Delphi等高级语言编写数据库应用程序时,往往需要用户自己在控制面板中配置ODBC数据源.对于一般用户而言,配置ODBC数据源可能是一件比较困难的工作.而且,在实际应用中,用户往往 ...
- bash shell最基本的语法
1 shell语句的基本构成 shell每个基本的构成元素之间都相隔一个空格. 比如[ -e file ],[.-e.file.]这四个基本元素之间都相隔了一个空格. 同样的道理[ ! -e file ...
- ivy
ivy https://ant.apache.org/ivy/ Apache Ivy™ is a popular dependency manager focusing on flexibility ...
- 正则工具类以及FinalClass
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/27811103 完整版见https://jadyer. ...
- Deep Learning 36:python中的一些函数
1.map(function, sequence[, sequence, ...])函数:返回一个list作用:map的作用是以参数序列中的每一个元素调用function函数,返回包含每次functi ...
- Why you shouldn’t connect your mobile application to a database
BY CRAIG CHAPMAN · PUBLISHED 2015-07-02 · UPDATED 2015-07-02 Working at Embarcadero, I frequently ...
- IDHTTP用法详解 good
一.IDHTTP的基本用法 IDHttp和WebBrowser一样,都可以实现抓取远端网页的功能,但是http方式更快.更节约资源,缺点是需要手动维护cook,连接等 IDHttp的创建,需要引入ID ...
- jconsole工具检测堆内存变化的使用
jconsole将Java写的程序检测. 从Java 5开始 引入了 JConsole.JConsole 是一个内置 Java 性能分析器,可以从命令行或在 GUI shell 中运行.您可以轻松地使 ...
- 一步一步学Silverlight 2系列(22):在Silverlight中如何用JavaScript调用.NET代码
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...