Hdu 4662 MU Puzzle

Source: Internet
Author: User

 

MU Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1296 Accepted Submission (s): 539



Problem Description Suppose there are the symbols M, I, and U which can be combined to produce strings of symbols called words. we start with one word MI, and transform it to get a new word. in each step, we can use one of the following transformation rules:
1. Double any string after the M (that is, change Mx, to Mxx). For example: MIU to MIUIU.
2. Replace any III with a U. For example: MUIIIU to MUUU.
3. Remove any UU. For example: MUUU to MU.
Using these three rules is it possible to change MI into a given string in a finite number of steps?

Input First line, number of strings, n.
Following n lines, each line contains a nonempty string which consists only of letters 'M', 'I and U '.

Total length of all strings <= 106.
Output n lines, each line is 'yes' or 'no '.
Sample Input
2MIMU

Sample Output
YesNo

Source 2013 Multi-University Training Contest 6
Recommend zhuyuanchen520 | We have carefully selected several similar problems for you: 4822 4821 4820 4819 4818
Regular questions, convert all u into I, and write more to find the regular

 

 

#include
 
  #include
  
   using namespace std;char str[1000010];int main(){int n;cin>>n;while(n--){cin>>str;int l=strlen(str),xi=0,xu=0,k=0;if(str[0]!='M'){cout<
   
    

 

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.