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

【题意】



给你n-k+1个限制

要求

a[i]..a[i]+k-1里面有相同的元素,或全都不同;

让你输出可能的一个序列

【题解】



先找到YES的一段

(找不到就全都输出一样的);

然后以这段YES作为种子

假设YES的段为pos..pos+k-1

往左往右构造

如果往左构造的话

就是for (int i = pos-1;i>=1;i–)

接下来要给第i个位置确定数字;

则如果i..i+k-1为YES的话

就取[i..i+k-1]中最小的未出现的那个数字;

如果i..i+k-1为NO的话

就取ans[i]=ans[i+k-1];

这样

ans[i..i+k]全都是不一样的;

就不会对再往左的答案造成影响.

往右的话

YES的情况相同

NO的情况变成ans[i]取ans[i-k+1]了.



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 50 + 20; int n, k, cnt1, po;
int ok[N], ans[N];
int bo[N];
char s[6];
string tar[N]; void in()
{
rei(n), rei(k);
rep1(i, 1, n - k + 1)
{
scanf("%s", s);
if (s[0] == 'N')
ok[i] = 0;
else
{
ok[i] = 1;
cnt1++;
po = i;
}
}
} void zhitrue(int pos, int l, int r)
{
rep1(i, 0, n)
bo[i] = 0;
rep1(i, l, r)
bo[ans[i]]++;
int x = 0;
while (bo[x]) x++;
ans[pos] = x;
} void zhifalse(int pos, int l, int r,int p)
{
if (p == 1)
{
ans[pos] = ans[r];
}
else
{
ans[pos] = ans[l];
}
} void ga()
{
if (cnt1 == 0)
{
rep1(i, 1, n)
ans[i] = 1;
}
else
{
rep1(i, po, po + k - 1)
zhitrue(i, po, po + k - 1);
rep2(i, po - 1, 1)
{
if (ok[i])
zhitrue(i, i, i + k - 1);
else
zhifalse(i, i, i + k - 1,1);
}
rep1(i, po + k, n)
{
if (ok[i])
zhitrue(i, i - k + 1, i);
else
zhifalse(i, i - k + 1, i,0);
}
}
} void init()
{
rep1(i, 1, 26)
{
char t = i + 'A' - 1;
tar[i] = "";
tar[i] += t;
tar[i] = t;
}
rep1(i, 1, 24)
{
char t1 = i + 'A' - 1, t2 = i + 'a' - 1;
tar[i + 26] = "";
tar[i + 26] += t1;
tar[i + 26] += t2;
}
} void o()
{
rep1(i, 1, n)
{
cout << tar[ans[i]];
if (i == n)
puts("");
else
putchar(' ');
}
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
init();
in();
ga();
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 791C】Bear and Different Names的更多相关文章

  1. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【codeforces 791D】 Bear and Tree Jumps

    [题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...

  3. 【codeforces 791B】Bear and Friendship Condition

    [题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是 ...

  4. 【codeforces 791A】Bear and Big Brother

    [题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...

  5. 【19.05%】【codeforces 680D】Bear and Tower of Cubes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【Codeforces 385C】Bear and Prime Numbers

    [链接] 我是链接,点我呀:) [题意] f[i]表示在x[]中有多少个数字是i的倍数 让你求出sum(f[i]) li<=i<=ri 且i是质数 [题解] 做筛法求素数的时候顺便把素数i ...

  7. 【Codeforces 639B】Bear and Forgotten Tree 3

    [链接] 我是链接,点我呀:) [题意] [题解] 首先,因为高度是h 所以肯定1下面有连续的h个点依次连成一条链.->用了h+1个点了 然后,考虑d这个约束. 会发现,形成d的这个路径,它一定 ...

  8. 【Codeforces 639A】Bear and Displayed Friends

    [链接] 我是链接,点我呀:) [题意] [题解] 时刻维护一下前K大的数字就好. 因为k<=6 然后数字不会减少只会增加. 因此只要维护一个大小为k的数组就ok. 保证这个数组是有序的. 写个 ...

  9. 【CodeForces 574B】Bear and Three Musketeers

    [链接] 我是链接,点我呀:) [题意] [题解] 枚举每一条边(x,y) 然后再枚举y的出度z 看看g[x][z]是否等于1(表示联通) 如果等于1就说明找到了一个三元环,则尝试用它们的出度和-6更 ...

随机推荐

  1. LuceneIndexFileDeleter会保留初始的commit

    给实时索引加入了merge策略,持续更新时发现有做merge,但索引文件夹中的段数远远大于RealTimeIndexWriter中的段数,就是有些merge的段应该删除,文件夹中没有删除.而关闭sea ...

  2. 添加asp.net mvc到现有的asp.net web form 应用程序

    前言 asp.net mvc的前一版本为asp.net web Form(Asp.net mvc之前称为asp.net),其第一个版本与2002年年初发布.asp.net web form 属于.ne ...

  3. 【MemSQL Start[c]UP 3.0 - Round 1 C】 Pie Rules

    [链接]h在这里写链接 [题意] 在这里写题意 [题解]     dp[i][0] 第i个位置,bob没有决策权     dp[i][1] 第i个位置,bob有决策权     dp[n][0] = 0 ...

  4. C++学习笔记(达内视频版)

    达内C++(陈宗权主讲) 第一天: 课程分为Core C++(标准C++.不依赖操作系统)和Unix C++. 1.配置bash,运行.sh文件. vi bash_profile 在"pat ...

  5. 在Qtcreator中,KDE的Hello World(安装kdelibs5-dev)

    我刚开始为KDE编程,我面临的问题是我不知道KDE项目的pro文件是什么,我有一个想法. 我还尝试了 file: 库 += -lkdeui 我还是找不到KApplication的问题 代码 main. ...

  6. 结合Wireshark捕获分组深入理解TCP/IP协议栈之HTTP协议

    摘要:     本文简单介绍了Web应用层协议理论知识,详细讲述了HTTP请求报文和响应报文各个字段含义,并从Wireshark俘获分组中选取HTTP相关报文进行分析. 一.概述     Web的应用 ...

  7. hdu Minimum Transport Cost(按字典序输出路径)

    http://acm.hdu.edu.cn/showproblem.php? pid=1385 求最短路.要求输出字典序最小的路径. spfa:拿一个pre[]记录前驱,不同的是在松弛的时候.要考虑和 ...

  8. HDU 1013 Digital Roots 题解

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

  9. JAVA Concurrent包 中的并发集合类

    我们平时写程序需要经常用到集合类,比如ArrayList.HashMap等,但是这些集合不能够实现并发运行机制,这样在服务器上运行时就会非常的消耗资源和浪费时间,并且对这些集合进行迭代的过程中不能进行 ...

  10. Java链接Redis时出现 “ERR Client sent AUTH, but no password is set” 异常的原因及解决办法

    Java链接Redis时出现 "ERR Client sent AUTH, but no password is set" 异常的原因及解决办法 [错误提示] redis.clie ...