codeforce771B Bear and Different Names 贪心or思维
来源:互联网 发布:csol租号软件 编辑:程序博客网 时间:2024/05/17 02:57
题目:
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.
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 1to 10.
If there are multiple valid solutions, print any of them.
8 3NO NO YES YES YES NO
Adam Bob Bob Cpqepqwer Limak Adam Bob Adam
9 8YES NO
R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc
3 2NO NO
Na Na Na
后来在草稿纸上画了画,大概是因为这样做满足前面而不影响后面。
策略:
对于i...i+k.(i=1,2,n-k+1).
如果是"YES",那么我就在i+k处新增加一个名字。
否则,我就让i+k处的名字等于i处的名字。
对了,还有在处理名字时可以先用数字代替,比较方便,然后再将数字转化成名字。
code:
#include<cstdio>
#include<cstring>
#include<map>
#include<string>
#include<iostream>
using namespace std;
const int MAXN=55;
int num[MAXN];
int main(void){
int n,k;scanf("%d%d",&n,&k);
char s[5];scanf("%s",s);
int tot=1,i=1;
if(s[0]=='Y'){
for(i=1;i<=k;++i)
num[i]=tot++;
}else{
for(i=1;i<=k-1;++i)
num[i]=tot++;
num[i++]=1;
}
for(int j=2;j<=n-k+1;++j){
char s[5];scanf("%s",s);
if(s[0]=='Y'){
num[i++]=tot++;
}else{
num[i]=num[i-k+1];
++i;
}
}
/*for(int i=1;i<=n;++i)printf("%d\t",num[i]);*/
for(int i=1;i<=n;++i){
string s;
bool flag=false;
while(num[i]){
if(!flag){s+='A'+num[i]%10;flag=true;}
else s+='a'+num[i]%10;
num[i]/=10;
}
cout<<s<<" ";
}
printf("\n");
}
- codeforce771B Bear and Different Names 贪心or思维
- Bear and Different Names
- Codeforces Round #405 C. Bear and Different Names (思维)
- Codeforces Round #405 C.Bear and Different Names【思维】
- Codeforces 791 C. Bear and Different Names【贪心】
- (贪心)Codeforces Round #405 C. Bear and Different Names
- codeforces Bear and Different Names
- C. Bear and Different Names
- codefroces 791C Bear and Different Names
- CodeForces 791C Bear and Different Names
- CodeForces 791C Bear and Different Names
- (codeforces)B. Bear and Different Names
- Codeforces791 C. Bear and Different Names
- Codeforces 791C Bear and Different Names 简单构造
- Codeforces 771B Bear and Different Names[构造]
- Codeforces Round #405 C. Bear and Different Names
- Codeforces 639C Bear and Polynomials 【思维】
- Codeforces 574C Bear and Poker【思维】
- Java线程同步
- 把Qt的值传给OpenGL
- grails 常用查询
- HDU
- Window环境MatConvNet安装
- codeforce771B Bear and Different Names 贪心or思维
- 114
- 带宽
- 生物信息实用数据库与论坛
- 59条令人捧腹但真实的程序员编程语录
- JavaScript基础语法
- oracle将一个字段拆分成多个值(regexp_substr函数)
- linux alias命令使用笔记
- JavaScript二叉查找树删除节点的实现原理