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# 复制文件夹内所有文件到另外一个文件夹
/// <summary> /// 开始转移 /// </summary> /// <param name="sender"></para ...
- chezmoi 使用
chezmoi(发音 /ʃeɪ mwa/ (shay-moi)):在多台不同的机器上安全地管理你的 dotfiles. 安装 macOS: brew install chezmoi Ubuntu: s ...
- Encoder-Decoder、Seq2Seq、Attention
Encoder-Decoder.Seq2Seq.Attention 传送门1:Encoder-Decoder 和 Seq2Seq 因为注意力不集中,所以这篇随笔就是看别人的文章,随手参考写写的. 1. ...
- 终于有人把Modbus讲明白了
大家好!我是付工. 2012年开始接触Modbus协议,至今已经有10多年了,从开始的懵懂,到后来的顿悟,再到现在的开悟,它始终岿然不动,变化的是我对它的认知和理解. 今天跟大家聊聊关于Modbus协 ...
- Angular – CLI
前言 一年半没有写 Angular 了. 现在又要开始写了. 复习过程中也顺便整理一下笔记呗. 介绍 CLI 是 Angular 的辅助工具. 输入一些 command 它会帮你 create 一些有 ...
- CSS – 实战 Color
前言 之前 W3Schools 学习笔记 (1) 也记入过 Color, 这篇整理一下在网页开发中, 颜色是如果被处理的. 网页都有什么颜色? 网页篇幅最大的颜色, 通常是来自图片, 不管是背景图, ...
- EF Core – Temporal Table 时态表
前言 EF core 6.0 开始有 build-in 的 Temporal Table 支持了. 关于 SQL Server Temporal Table 可以看这篇. 主要参考 What's Ne ...
- .NET 的 Native AOT 现在是什么样的?
今天要写的这篇文章源自昨天在朋友圈发的文章<UWP 通过 .NET 9 和Native AOT 的支持实现 UWP 应用的现代化>[1],一位小伙伴的对话让我想全面梳理下Native AO ...
- SQL通用语法与分类
通用语法 1.SQL可以单行或多行书写,以分号结尾. 2.MySQL数据库的SQL语句不区分大小写,关键字建议使用大写. 3.注释 1)单行注释: -- 注释内容 或 # 注释内容(MySQL特有) ...
- SqlEs-像使用数据库一样使用Elasticsearch
SqlEs SqlEs是Elasticsearch的客户端JDBC驱动程序,支持采用sql语法操作Elasticsearch.SqlEs构建在RestHighLevelClient,屏蔽了RestHi ...