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. 【CMake系列】10-cmake测试集成googletest与第三方库自动化构建

    cmake测试,使用ctest 可能不能满足我们的需求,需要我们使用更为强大的第三方测试框架,如googletest,完成项目中的测试工作 本篇文章将第三方测试框架 googletest,引入,同时也 ...

  2. Hexo-GitHub部署魔改第一步-config

    Hexo-GitHub部署魔改第一步_config.yml 1. config.yml # Hexo Configuration ## Docs: https://hexo.io/docs/confi ...

  3. Es java API官网手册

    官方地址: 一.TransportClient客户端 https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.5/index.h ...

  4. 对GEE下载时分块影像进行镶嵌(GDAL)

    前言 GDAL自带的镶嵌功能比较单一,只能将图像简单拼接到一起,不能实现直方图匀色以及羽化等功能,但是对GEE导出的分块影像进行镶嵌较为适合. 优点: 使用代码,镶嵌多个影像较为简便 GDAL较为稳定 ...

  5. cesium的使用

    安装 建议使用vue的cesium插件:vue-cli-plugin-cesium.vue add命令可零配置添加cesium:vue add vue-cli-plugin-cesium 报错 添加完 ...

  6. 忘记 mysql 8.0 root 密码 怎么修改

    本文copy自 Centos7重置Mysql 8.0.1 root 密码 问题产生背景: 安装完 最新版的 mysql8.0.1后忘记了密码,向重置root密码:找了网上好多资料都不尽相同,根据自己的 ...

  7. 深入理解JavaScript中的try catch finally

    在日常开发中,我们经常使用try catch 来捕捉错误,来提升应用程序的健壮性,但是,大部分时候,只是惯性使用,很少静下来去深入理解一下try catch finally,所以本文将对try cat ...

  8. webpack笔记-loader的详细使用介绍(四)

    loader 基本上都是第三方类库,使用时需要安装,有一些 loader 还需要安装额外的类库,例如 less-loader 需要 less,babel-loader 需要 babel 等. load ...

  9. DOM – IntersectionObserver

    介绍 IntersectionObserver 的作用是监听某个元素是否出现在框内 (比如 viewport). 它可以实现 lazy load image, 一开始图片是没有加载的, 当图片出现在 ...

  10. dfs 【XR-2】奇迹——洛谷5440

    问题描述: 现有一个八位数,从左往右分别代表年月日,例如20240919,代表2024年9月19日,现将该八位数蒙住几位数,问填入数字之后有几种情况是的日为质数,月+日为质数,年+月+日为质数 输入: ...