Rikka with string BC#37

Rikka with string

Accepts: 395

Submissions: 2281

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/65536 K (Java/Others)

问题描述

众所周知,萌萌哒六花不擅长数学,所以勇太给了她一些数学问题做练习,其中有一道是这样的:

有一天勇太得到了一个长度为n的字符串,但是六花一不小心把这个字符串搞丢了。于是他们想要复原这一个字符串。勇太记得这个字符串只包含小写字母而且这个串不是回文串。然而不幸的是他已经不记得这个字符串中的一些字符了,你可以帮他复原这个字符串吗?

当然,这个问题对于萌萌哒六花来说实在是太难了,你可以帮帮她吗?

输入描述

多组数据,数据组数不超过20,每组数据第一行两个正整数n。接下来一行一个长度为n的只包含小写字母和’?’的字符串,’?’表示勇太已经忘了这一个位置的字符了。

1≤n≤103

输出描述

每组数据输出仅一行一个长度为n的仅包含小写字母的字符串,如果有多种合法解,请输出字典序最小的,如果无解,请输出”QwQ”

输入样例

5

a?bb?

3

aaa

输出样例

aabba

QwQ

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<cstdlib>
#include<set>
#include<stack>
#include<cstring>
using namespace std;
template<class T>inline T read(T&x)
{
    char c;
    while((c=getchar())<=32)if(c==EOF)return 0;
    bool ok=false;
    if(c=='-')ok=true,c=getchar();
    for(x=0; c>32; c=getchar())
        x=x*10+c-'0';
    if(ok)x=-x;
    return 1;
}
template<class T> inline T read_(T&x,T&y)
{
    return read(x)&&read(y);
}
template<class T> inline T read__(T&x,T&y,T&z)
{
    return read(x)&&read(y)&&read(z);
}
template<class T> inline void write(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x<10)putchar(x+'0');
    else write(x/10),putchar(x%10+'0');
}
template<class T>inline void writeln(T x)
{
    write(x);
    putchar('\n');
}
//-------ZCC IO template------
const int maxn=100001;
const double inf=999999999;
#define lson (rt<<1),L,M
#define rson (rt<<1|1),M+1,R
#define M ((L+R)>>1)
#define For(i,t,n) for(int i=(t);i<(n);i++)
typedef long long  LL;
typedef double DB;
typedef pair<int,int> P;
#define bug printf("---\n");
#define mod 10007
int n;
char a[maxn];
bool pan(char *s)
{
    for(int i=0; i<=n/2; i++)
    {
        if(a[i]!=a[n-1-i])return true;
    }
    return false;
}

int b[maxn];

int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("in.txt","r",stdin);
//    #endif // ONLINE_JUDGE
    int m,i,j,k,t;
    while(read(n))
    {
        scanf("%s",a);
        memset(b,0,sizeof(b));
        bool flag=false;
        for(i=0,j=0; i<n; i++)if(a[i]=='?')
            {
                flag=true;
                b[j++]=i;
            }
        if((!flag&&!pan(a))||(!pan(a)&&n%2==1&&a[n/2]=='?'&&j==1))
        {
            puts("QwQ");
        }
        else
        {
            bool ok=false;
            for(i=0;i<n;i++)if(a[i]=='?')a[i]='a';
            for(i=j-1; i>=0; i--)
            {
                for(char k='a'; k<='z'; k++)
                {
                    a[b[i]]=k;
                    if(pan(a))
                    {
                        ok=true;
                        break;
                    }
                }
                if(ok)
                    break;
                else
                    a[b[i]]='a';
            }
            puts(a);
        }
    }
    return 0;
}
时间: 2024-10-12 21:01:16

Rikka with string BC#37的相关文章

HDU - 5202 - Rikka with string (DFS)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 214    Accepted Submission(s): 109 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation

HDU 5202 Rikka with string (水DFS)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 624    Accepted Submission(s): 243 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation

HDU 6086 Rikka with String

Rikka with String http://acm.hdu.edu.cn/showproblem.php?pid=6086 题意: 求一个长度为2L的,包含所给定的n的串,并且满足非对称. 分析: AC自动机+状压dp. 首先给这个n个串,建立AC自动机.然后去枚举长度为L的一个串,就可以知道另一半了. 如果给定的串完全存在于左边或者右边,那么直接往AC自动机加入这个串或者取反后的反串.如果是跨越中间,那么暴力的把所有的串,从中间切开,然后判断是否合法,加入到AC自动机上就行,如果长度枚举

hdu 5202 Rikka with string(模拟)

Rikka with string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 625    Accepted Submission(s): 244 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation

hdoj - 5202 Rikka with string (BestCoder Round #37 ($))

http://acm.hdu.edu.cn/showproblem.php?pid=5202 字符串处理的题,要细心. 给定一个只包含小写字母和问号的字符串,让我们还原出本来的字符串,把问号替换成任意字符,如果有多种可能输出字典序最小的,原字符串不能是回文串. 首先判断有没有非法字符,然后是否包含问号,如果没有包含则判断是否是回文串,满足则表示不能还原 . 否则把所有问号都替换成‘a',但是可能构成回文,然后继续替换,直到不是回文为止. 1 #include <iostream> 2 #inc

BestCoder #37 Rikka with string (hdu 5205)

// 这题一开始看的时候觉得就是取最右边的问号,依次从大到小枚举 // 注意没有?和?在中间的情况特判,结果wa了十一发,还是没有找到 // 错误在哪里,看了一下discuss里面的数据发现5 b??ab这组用我先开始 // 的思路是跪了的.我的会输出QwQ... // // 然后看了看大牛们的思路,发现自己所谓的最右边是错的,这题要求字典序最小 // 可以先全部把?填成a,判断是否回文, // 如果不是回文直接输出, // 如果是回文,那么我们可以直接把最右边的不是中间的填成b,输出就好了 /

hdu 5202 Rikka with string (dfs )

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now

ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)

Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: One day, Yuta got a string which contains n letters but Rikka lost it in accident. Now

Rikka with string

Accepts: 395 Submissions: 2281 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practic