Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Wordtime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.
Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
InputThe first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
OutputIf there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.
If there are multiple solutions, you may print any of them.
ExamplesinputABC??FGHIJK???OPQR?TUVWXY?outputABCDEFGHIJKLMNOPQRZTUVWXYSinputWELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWOoutput-1input??????????????????????????outputMNBVCXZLKJHGFDSAQPWOEIRUYTinputAABCDEFGHIJKLMNOPQRSTUVW??Moutput-1NoteIn the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.
In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1.
In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
题目链接:
http://codeforces.com/contest/716/problem/B
题目大意:
给你一个长度为N(N<=100000)只含大写字母和'?'的字符串,其中'?'可以被任意大写字母替换,问这个字符串是否能够含有一个连续的长度为26的子串,使得每个大写字母只出现一次。
题目思路:
【模拟】
枚举左右端点I和J,并且记录最后一个大写字母出现的位置,如果这个字母已经出现过并且最后出现的位置X在I之后,那么直接把I移动到X+1,继续做,直到I~J的长度为26
接下来对于'?'只要从I到J依次填入没出现过的字母,其余不在I~J的随意填。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 50004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
char s[N];
int mark[];
int main()
{
#ifndef ONLINE_JUDGEW
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
n=strlen(s);
mem(mark,-);
if(n<){puts("-1");continue;}
for(i=,j=;j<n;j++)
{
if(s[j]=='?')
{
if(j-i==)break;
continue;
}
k=s[j]-'A';
if(mark[k]!=-)
{
i=max(i,mark[k]+);
mark[k]=j;
}
else mark[k]=j;
if(j-i==)break;
}
if(j==n || j-i<)puts("-1");
else
{
x=;
for(k=i;k<=j;k++)
{
if(s[k]=='?')
{
for(;x< && mark[x]>=i;x++);
s[k]=x+'A';mark[x]=i;
}
}
for(i=;i<n;i++)
if(s[i]=='?')s[i]='A';
puts(s);
}
}
return ;
}
/*
// //
*/
Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))的更多相关文章
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- Codeforces Round #372 (Div. 2)
Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...
- 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 B C 水 暴力/模拟 构造
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))
B. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #372 (Div. 1) B. Complete The Graph (枚举+最短路)
题目就是给你一个图,图中部分边没有赋权值,要求你把无权的边赋值,使得s->t的最短路为l. 卡了几周的题了,最后还是经群主大大指点……做出来的…… 思路就是跑最短路,然后改权值为最短路和L的差值 ...
随机推荐
- day01-day04总结- Python 数据类型及其用法
Python 数据类型及其用法: 本文总结一下Python中用到的各种数据类型,以及如何使用可以使得我们的代码变得简洁. 基本结构 我们首先要看的是几乎任何语言都具有的数据类型,包括字符串.整型.浮点 ...
- WebForm开发常用代码
1.获取服务器绝对路径: public static string GetMapPath(string strPath) { if (HttpContext.Current != null) { re ...
- 关于this 的一个问题
var name = "the window"; var object = { name:"my object"; getName:function(){ re ...
- heibernate增删改查总结一下自己的不足
难点也就我不熟悉的是数据库语句的书写,要加强复杂查询语句的书写 /* 简单的在共享类中已经可以用的了 * 总结: * * --------------------------------------查 ...
- 国内流行的两大开源.net微信公众平台SDK对比分析
最近忙于微信周边的开发 难免手痒去搜索一下有没有相关的sdk直接拿来使 还真发现了不少 这里总结两个看起来比较不错的.net平台下基于C#语言开发的SDK 一个强大一个小巧 (1) Senparc.W ...
- Android中全局搜索(QuickSearchBox)详解
http://blog.csdn.net/mayingcai1987/article/details/6268732 1. 标题: 应用程序如何全面支持搜索 2. 引言: 如果想让某个应用程序支持全局 ...
- Android常用第三方框架
1.volley (截击) 项目地址 https://github.com/smanikandan14/Volley-demo (1) JSON,图像等的异步下载: (2) 网络请求的排序(sch ...
- CTE-递归[2]
在此之前写过一个CTE的递归,取出了所有的子节点,基本上可以满足大多数的需求,这里我们来延伸一下:首先我们回顾下原来的场景 图片的上半部分递归查出某个节点的所有子节点,这个我们已经通过CTE实现了,可 ...
- html招聘简历解析并入库测试
1.解析4天,一天用来熟悉Jsoup 2.入库,需要熟悉什么样的格式代码可以入库,将自己解析好的代码转为指定格式.总体框架的构建, 如何执行,需要读他人写的代码(很费时间).4天,包括晚上九点加班三天 ...
- 【转】 iOS开发之手势gesture详解
原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...