CF716B Complete the Word 题解
CF716B Complete the Word 题解
分析
首先观察数据范围是 \(50000\),可以考虑 \(O(n)\) 暴力。
在字符串中枚举子串开始的位置 \(i\),然后再枚举 \(i\) 到 \(i+25\),开个桶统计每个大写字母出现的次数,如果大于 \(1\) 就直接 break。统计完之后剩下的就都是问号了,可以随便填,所以这个子串是一定合法的。用 \(ans\) 来截取这一段合法子串,\(st\) 记录 \(ans\) 的起始位置,方便输出。如果所有子串都枚举完没有合法的,输出 \(-1\) 即可。
输出时没到子串 \(ans\) 时输出原串,问号随便输出。枚举到 \(st\) 时就输出 \(ans\),问号处缺啥填啥。
代码
代码过长,参考为主,不喜勿喷
#include <bits/stdc++.h>
using namespace std;
namespace Raiden
{
int t[30];
signed work()
{
string s, ans;
int st;
cin >> s;
if (s.size() < 26)
cout << -1 << endl, return 0;
bool flag = 1;
for (int i = 0; i <= s.size() - 26; i++)
{
flag = 1;
memset(t, 0, sizeof(t));
for (int j = i; j < i + 26; j++)
{
if (s[j] != '?')
{
if (t[s[j] - 'A'] > 0)
flag = 0, break;
t[s[j] - 'A']++;
}
}
if (flag)
{
ans = s.substr(i, 26);
st = i;
break;
}
}
if (!flag)
cout << -1 << endl, return 0;
for (int i = 0; i < s.size(); i++)
{
if (i == st)
{
for (auto it : ans)
{
if (it == '?')
{
for (int i = 0; i < 26; i++)
if (t[i] == 0)
{
cout << char(i + 'A');
t[i]++;
break;
}
}
else
cout << it;
}
i = st + 25;
}
else
{
if (s[i] == '?')
cout << 'A';
else
cout << s[i];
}
}
return 0;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
return Raiden::work();
}
CF716B Complete the Word 题解的更多相关文章
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- codeforces 372 Complete the Word(双指针)
codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...
- Complete the Word CodeForces - 716B
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring ...
- Complete the Word
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring ...
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- Codeforces Round #372 +#373 部分题解
用了两场比赛上Div 1感觉自己好腊鸡的说...以下是这两场比赛的部分题解(不得不说有个黄学长来抱大腿还是非常爽的) Round #372 : Div 2 A:Crazy Computer 题意:给定 ...
- CodeForces 715B Complete The Graph 特殊的dijkstra
Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...
- Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
随机推荐
- Windows中Powershell中的 rm -rf 等效命令
Remove-Item -Recurse -Force <要删除的目录> 可以简写为: rm -r -fo <要删除目录>
- Nuitka打包
Nuitka打包PySide6/PyQt 本文仅供本人知识总结使用,所以内容会比较浅显,不喜勿喷. 文章目录 Nuitka打包PySide6/PyQt 一.需要C++编译器 二.安装Nuitka 三. ...
- BibTeX 和 BibLaTeX
BibTeX:传统的参考文献处理工具,使用 .bst 文件来定义参考文献的样式. BibLaTeX:功能更强大且更现代的工具,使用 .bbx..cbx 和 .dbx 文件来定义参考文献和引用的样式. ...
- Kubernetes-3.2:kubespray安装高可用k8sv1.20.2集群及常见报错解决
kubespray安装高可用k8s集群 环境介绍 系统环境 主机名 / IP地址 角色 内核版本 CentOS 7.6.1810 master1 / 192.168.181.252 master &a ...
- C# 模拟http请求出现 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作[windows服务器]
系统里面用到C#模拟Http请求,上线到服务器后,发现日志中大量出现"由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作" 或"通常每个套接字地址(协议/网络地址/ ...
- 【YashanDB数据库】YashanDB如何回收表空间
确认表空间高水位线,是否有可回收空间. select a.tablespace_name,a.high_water_mark,b.user_bytes,b.total_bytes from (SELE ...
- 音视频处理三剑客之 AEC:回声产生原因及回声消除原理
在上一期课程<音视频开发者进阶 -- 音频要素>中,我们从声音三要素.音频模拟信号的数字化和音频数字信号特征等方面,重新认识了"声音"这个老朋友.今天,我们会进一步聊聊 ...
- OData – How It Work
前言 OData 是很冷门的东西, 用的人少, 开发的人少, 文档自然也少的可怜. 如果真的想用它, 多少要对它机制有点了解. 这样遇到 bug, 想扩展的时候才不至于完全没有路. 主要参考: ODa ...
- 信创环境经典版SuerMap iManager启动崩溃
一.问题环境 操作系统:银河麒麟kylin V10 CPU:鲲鹏920 SuperMap iManager 10.2.1 硬件:16H64G机器 二.现象 磁盘和内存都有空闲,首次启动SuperMap ...
- 信创环境经典版SuperMap iManager监控外部SuperMap iServer资源失败,无法监控目标GIS服务器CPU与内存使用情况
一.问题环境 操作系统:银河麒麟kylin V10 CPU:鲲鹏920 SuperMap iServer 10.2.0 SuperMap iManager 10.2.1 二.现象 部署完经典版Supe ...