codeforces 55 div2 C.Title 模拟
2 seconds
256 megabytes
standard input
standard output
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first k Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left.
Vasya has already composed the approximate variant of the title. You are given the title template s consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.
The first line contains an integer k (1 ≤ k ≤ 26) which is the number of allowed alphabet letters. The second line contains s which is the given template. In s only the first k lowercase letters of Latin alphabet and question marks can be present, the length of s is from 1 to 100 characters inclusively.
If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first k letters of the Latin alphabet. At that, each of those k letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if exists such an i (1 ≤ i ≤ |s|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |s| stands for the length of the given template.
3
a?c
IMPOSSIBLE
2
a??a
abba
2
?b?a
abba
题意:需要使用n个字符得到一个字典序最小的回文串;
思路:先预处理出含有的字母,跟?是不是根据回文可以得到;
从中间往前遍历,如果可以用未出现的最大的字母填入,否则用最小的字母填;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 100000000000005
#define MAXN 10000010
#define pi 4*atan(1)
#define esp 0.000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
char a[];
int flag[],ans;
void init(int len)
{
for(int i=;i<=len/;i++)
{
if(a[i]=='?'&&a[len-i-]!='?')
a[i]=a[len-i-],flag[a[len-i-]-'a']=;
if(a[i]!='?'&&a[len-i-]=='?')
a[len-i-]=a[i],flag[a[i]-'a']=;
if(a[i]!='?'&&a[len-i-]!='?')
flag[a[i]-'a']=;
}
for(int i=;i<len/;i++)
{
if(a[i]!=a[len-i-]&&a[i]!='?')
{
ans=;
return;
}
}
}
int getsum(int x)
{
int sum=;
for(int i=;i<x;i++)
sum+=flag[i];
return sum;
}
int first(int x)
{
int i;
for(i=x-;i>;i--)
{
if(flag[i]==)
return i;
}
return i;
}
int main()
{
int x,y,z,i,t;
ans=;
scanf("%d",&x);
scanf("%s",a);
int len=strlen(a);
init(len);
if(ans)
{
printf("IMPOSSIBLE\n");
return ;
}
for(i=len/;i>=;i--)
{
if(a[i]=='?')
{
z=first(x);
a[i]=a[len-i-]=z+'a';
flag[z]=;
}
}
if(getsum(x)==x)
printf("%s\n",a);
else
printf("IMPOSSIBLE\n");
return ;
}
codeforces 55 div2 C.Title 模拟的更多相关文章
- Codeforces 583 DIV2 Asphalting Roads 模拟
原题链接:http://codeforces.com/problemset/problem/583/A 题意: 很迷很迷,表示没看懂..但是你看样例就秒懂了 题解: 照着样例模拟就好 代码: #inc ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
随机推荐
- jquery.js与sea.js综合使用
jquery.js与sea.js综合使用 目录 模块定义 define id dependencies factory exports require require.async require. ...
- Unity3D笔记四 基础知识概念
1. Project视图 主要存放游戏中用到的所有资源文件,常见的包括:游戏脚本.预设.材质.动画.自定义字体.纹理.物理材质和GUI皮肤等. 1> Folder: 文件夹,用于资源的分 ...
- thinkphp---数据表更新字段开发模式可更新生产模式不能更新!
这里认为是坑的主要原因:这个问题我调试了一天,才发现是缓存的问题. 问题原因:在做一thinkphp的项目,在后期要进行修改.修改的时候,数据表里面添加了两个字段,然后前台修改模板,将添加的字段提交上 ...
- windows本地环境如何用wamp配置多域名绑定访问
https://jingyan.baidu.com/article/acf728fd5fcdadf8e510a3e5.html
- 三维凸包求凸包表面的个数(HDU3662)
3D Convex Hull Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- redhat 6.6 离线安装docker
本机环境:redhat6.6 uname -a Linux host- -.el6.x86_64 # SMP Tue Sep :: EDT x86_64 x86_64 x86_64 GNU/Linux ...
- centos linux 系统日常管理4 scp,rsync,md5sum,sha1sum,strace ,find Rsync 常见错误及解决方法 第十七节课
centos linux 系统日常管理4 scp,rsync,md5sum,sha1sum,strace ,find Rsync 常见错误及解决方法 第十七节课 rsync可以增量同步,scp不行 ...
- 布局-EasyUI Panel 面板、EasyUI Tabs 标签页/选项卡、EasyUI Accordion 折叠面板、EasyUI Layout 布局
EasyUI Panel 面板 通过 $.fn.panel.defaults 重写默认的 defaults. 面板(panel)当做其他内容的容器使用.它是创建其他组件(比如:Layout 布局.Ta ...
- JOJ1202。重新操刀ACM,一天一练!做个简单的题目温习。
http://ac.jobdu.com/problem.php?pid=1202 题目描述: 对输入的n个数进行排序并输出. 输入: 输入的第一行包括一个整数n(1<=n<=100). ...
- 7.2 Models -- Defining Models
一.概述 1. 模型是一个类,它定义了你呈现给用户的数据的属性和行为.用户希望如果他们离开你的应用程序,并返回后(或如果他们刷新页面)看到的任何东西应该被一个model代表. 2. 确保在ember. ...