Hdu-5202-rikka with string (DFS + wronganswer)

Source: Internet
Author: User

Rikka with stringTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 937 Accepted Submission (s): 334


Problem Descriptionas We know, Rikka is poor at math. Yuta is worrying on this situation, so he gives Rikka some math tasks to practice. There is one of the them:


One day, Yuta got a string which contains n& #8201; letters but Rikka lost it in accident. Now they want to recover the string. Yuta remembers that the string was only contains lowercase letters and it was not a palindrome string. Unfortunately he cannot remember some letters. Can you help him recover the string?


It is too difficult for Rikka. Can you help her?
Inputthis problem have multi test cases (no more than - ). For each test case, the first line contains a number n ( 1 ≤ n ≤ 1000 " . The next line contains a n-length string which only contains lowercase letters and '? ', Haven place which Yuta are not sure .
Outputfor Each test cases print a n-length string–the string you come up with. In the than one string exists, print the lexicographically & #64257; rst one. In the case where no such string exists, output "QwQ".
Sample Input
5a?bb?3aaa

Sample Output
Aabbaqwq

Sourcebestcoder Round #37 ($)
Recommendhujie | We have carefully selected several similar problems for you:5213 5212 5211 5209 5208
1001 Rikka with stringIf there are no restrictions that are not palindrome, you can turn all of them into a, which must be the smallest dictionary order. And now there are palindrome string restrictions, we can from small to large enumeration of the most important not in the center of the string to choose what the question mark, the other question mark is still replaced by a, obviously if there is a solution, so that must be the smallest dictionary order solution. Note that there is no question mark and question mark in the case of a positive center. Complexity of Time
    
        O(n)    
  
 
    
 Hack point: Pretest is very strong, there is nothing to hack.

The official algorithm seems to be greedy, it seems to be good to understand, but there is a process I can not achieve ..... After reading the two diseases will not this problem, good sorrow! The blogger, there is no ac (bo master too Water), learn a zzuspy bo Friends of the Dfs way ... Anyway, write a blog first! Thank Acmer Zzuspy share his source!
Attached original address: http://blog.csdn.net/u014355480/article/details/45000903

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;char str[1005];int len; int Flag;int judge ()//Determine if it is a palindrome number!    {for (int i = 0; I <= len/2; i++) {if (Str[i]! = str[len-i-1]) return 1; } return 0;} void Dfs (int x)//dfs!                                             {if (flag = = 0) return;         Flag=0, that is, the recursive exit is to if (x = = len) {if (judge ()) <span style= "White-space:pre" ></span>//If not a palindrome number!            {printf ("%s\n", str);        Flag = 0;    } return; } if (str[x] <= ' z ' && str[x] >= ' a ')//not '? '        Down a search {DFS (x + 1);    Return    } if (str[x] = = '? ') {for (int i = ' a '; I <= ' z '; i++)///if '? '                                 Replace all {str[x] = (char) I with the dictionary order;              DFS (x + 1); After the replacement, continue down a deep search str[x] = '? ';        <span style= "White-space:pre" ></span>//Because each time only judge a question mark, so deep search to restore!    }}}int Main () {int n;        while (scanf ("%d", &n)! = EOF) {scanf ("%s", str);        len = strlen (str);        flag = 1;        DFS (0);        if (flag) {printf ("qwq\n"); }} return 0;}






Chinese test instructions are as follows:
Rikka with stringaccepts:395submissions:2281Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others) Problem description
As we all know, Meng Meng six flower is not good at maths, so Yong too gave her some math problems to do exercises, one of which is this: one day Yong too got a length for
    
        n   
  
 
    
 String, but the six flowers accidentally lost the string. So they want to recover this string. Yong remembers that this string contains only lowercase letters and that the strings are not palindrome strings. Unfortunately, he doesn't remember some of the characters in the string, can you help him recover the string? Of course, this question is very difficult for the six flowers, can you help her?
Enter a description
Multiple sets of data, no more than the number of data groups
    
        -   
  
 
    
 , the first row of two positive integers per group of data
    
        n   
  
 
    
 。 The next line is a length of
    
        n   
  
 
    
 Contains only lowercase letters and '? ' The string, '? ' It means that Yong has forgotten the character of this position.
   
    
        1≤n≤3  
 

    
   
Output description
Each set of data output is only one line of the length of a string of n only lowercase letters, if there are a number of legal solutions, output dictionary order is minimal, if there is no solution, please output "QwQ"
Input sample
5a?bb?3aaa
Output sample
Aabbaqwq



Hdu-5202-rikka with string (DFS + wronganswer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.