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 题解的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  4. codeforces 372 Complete the Word(双指针)

    codeforces 372 Complete the Word(双指针) 题链 题意:给出一个字符串,其中'?'代表这个字符是可变的,要求一个连续的26位长的串,其中每个字母都只出现一次 #incl ...

  5. Complete the Word CodeForces - 716B

    ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring  ...

  6. Complete the Word

    ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring ...

  7. CodeForces 716B Complete the Word

    题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...

  8. Codeforces Round #372 +#373 部分题解

    用了两场比赛上Div 1感觉自己好腊鸡的说...以下是这两场比赛的部分题解(不得不说有个黄学长来抱大腿还是非常爽的) Round #372 : Div 2 A:Crazy Computer 题意:给定 ...

  9. CodeForces 715B Complete The Graph 特殊的dijkstra

    Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...

  10. 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 ...

随机推荐

  1. MFC 静态拆分视图窗口

    今天学习了MFC中拆分窗口,现将方法记录下. 想要在窗口视图中拆分成左右两个视图窗口,首先要注意的是拆分后要加载到左右的视图要符合动态创建的类, 也就是要在自己创建的视图类中添加动态创建机制宏. 类内 ...

  2. PHP转Go系列 | ThinkPHP与Gin框架之Redis延时消息队列技术实践

    大家好,我是码农先森. 我们在某宝或某多多上抢购商品时,如果只是下了订单但没有进行实际的支付,那在订单页面会有一个支付倒计时,要是过了这个时间点那么订单便会自动取消.在这样的业务场景中,一般情况下就会 ...

  3. VUE-局部使用

    目录 VUE-局部使用 快速入门 常用指令 v-for v-bind v-if & v-show v-on v-model vue生命周期 Axios Vue案例 VUE-局部使用 Vue 是 ...

  4. Electron32-ViteOS桌面版os系统|vue3+electron+arco客户端OS管理模板

    基于electron32+vue3 setup+pinia2桌面端os管理解决方案ElectronVue3OS. vue3-electron32-os全新原创Electron32+Vite5+Vue3 ...

  5. 学习笔记:robots.txt文件

    1.1 介绍 robots.txt文件是一种用于指导搜索引擎爬虫在网站上哪些页面可以被抓取,哪些页面不应该被抓取的文本文件.这个文件通常放置在网站的根目录下. 1.2 由来 robots.txt标准最 ...

  6. linux修改limits.conf不生效

    正常情况下, /etc/security/limits.conf 的改动,重新登录就可以生效, 我遇到的问题最后的解决方案是重启虚拟机解决了,也参考了很多网上的文章,整理记录一下 一.修改方法 1.临 ...

  7. 【笔记】前端人脸检测之clmtrackr.js的使用

    clmtrackr.js使用示例代码 html代码: <div class="video-con"> <video id="video" pl ...

  8. CSS & JS Effect – Button Hover Bling Bling Effect

    效果 原理 一眼看上去, background 有渐变颜色 linear-gradient. 当 hover in 的时候有一束白光, 从右边移动到左边. hover out 则是反过来. 它其实是通 ...

  9. ASP.NET Core Library – Hangfire

    前言 以前写过 Hangfire 的学习笔记, 但写的很乱. 这篇做个整理. 介绍 Hangfire 是用来做 server task 的, 比如: background job, delay job ...

  10. C# – 10.0

    前言 之前写过 6.0, 7.0, 8.0, 9.0 总结. 10.0 也是有些好东西哦, 尤其是 pattern matching 的完善, 差不多是时候可以重构 if else switch 的写 ...