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 ...
随机推荐
- 看了这几个C语言例子,你一定和我一样连说5个卧槽,声音一次比一次大
曾经我一直以为自己C语言学的还挺好的,直到看到这几个例子. 例1 首先来看一下,大师是如何求圆周率的,一口君实在词穷,first卧槽. #include <stdio.h> long a= ...
- 什么是AOP,以及在Springboot中自定义AOP
AOP (Aspect Oriented Programming)一般译为面向切面编程 Aspect [ˈæspekt] n.方面;层面;(动词的)体那么AOP 面相切面编程具体是指什么,它和之前的O ...
- element-ui 表格控制列显隐简单方案
核心是使用v-if控制列的显隐 <template> <div> <div v-for="(item, index) in tables" :key= ...
- 组合数取模的几种方法--Exlucas&杨辉三角&组合
组合数取模的几个方法 求: \[C^{m}_{n} \bmod P \] 1.杨辉三角法 \[C^{m}_{n} = C^{m - 1}_{n - 1} + C^{ m }_{n - 1} \] 时间 ...
- ZeroTier 内网穿透
之前使用 FRP 进行内网穿透,缺点是需要公网 IP,而没有公网 IP 的我只好租了一台云服务器来作为 FRP Server.花钱不说,公网这台云服务器的带宽还很小,导致内网穿透体验并不怎么样.Zer ...
- Make 使用
GNU Make 参考:Make 命令教程 | 阮一峰的网络日志 Makefile 文件的格式 Makefile 文件由一系列 规则(rules)构成.每条 规则 的形式如下. <target& ...
- JMESPath 使用
最近在学习使用 AWS CLI,经常要用到 query 功能.AWS CLI 使用的查询语法是 JMESPath,因此特地在这里记录常用的 JMESPath 语法. JMESPath 是一种查询语言, ...
- 【DVWA】安全测试工具之BurpSuite
一.应用场景 二.安装软件 官网下载地址:https://portswigger.net/burp/releases 下载版本2021.7 注册机的 Github 项目地址:TrojanAZhen/B ...
- SVG Video 声音图标灰色,无法点击
原因:Video里的视频放的是录屏,怪不得声音图标是灰色的 换成正常有声音的mp4文件,声音图标就正常了
- R-Adapter:零样本模型微调新突破,提升鲁棒性与泛化能力 | ECCV 2024
大规模图像-文本预训练模型实现了零样本分类,并在不同数据分布下提供了一致的准确性.然而,这些模型在下游任务中通常需要微调优化,这会降低对于超出分布范围的数据的泛化能力,并需要大量的计算资源.论文提出新 ...