题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662

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
2
MI
MU
 
Sample Output
Yes
No
 
Source
 
Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:  4822 4821 4820 4819 4818 
 

规律题,把u所有化成i,然后多写下,就能发现规律

#include<iostream>
#include<cstring>
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<<"No"<<endl;
continue;
}
for(int i=1;i<l;i++)
{
if(str[i]=='I')
xi++;
else if(str[i]=='U')
xu++;
else
{
k=1;
break;
}
}
if(k==1 || ((xi+xu)%2==1 && !(xi==1 && xu==0)) || xi%3==0)
{
cout<<"No"<<endl;
continue;
}
else
{
cout<<"Yes"<<endl;
continue;
}
}
return 0;
}

hdu 4662 MU Puzzle的更多相关文章

  1. HDU 4662 MU Puzzle (2013多校6 1008 水题)

    MU Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU 4662 MU Puzzle:找规律

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 题意: 初始字符串为"MI". 有三个操作: (1)将'M'之后的所有字符翻 ...

  3. HDU 4662 MU Puzzle 数论或者水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4662 题目是问目标串能否由MI得到,我们可以逆向思维,目标串能否反过来处理得到MI,所以,首先排除M ...

  4. 【找规律】HDU 4662——MU Puzzle

    来源:点击打开链接 这个题目的来源是人工智能领域MU猜想.比赛的时候也参考了相关资料,可是最后差一点没有把规律推出来. 注意到以下几个性质.第一,MI怎么变换M永远只能在第一位.第二,因为变换时只能在 ...

  5. HDU 4662 MU Puzzle(找规律)

    题意:问是否能把MI通过以下规则转换成给定的字符串s. 1.使M之后的任何字符串加倍(即,将Mx更改为Mxx). 例如:MIU到MIUIU.2.用U替换任何III.例如:MUIIIU至MUUU.3.去 ...

  6. HDU 4662 MU Puzzle 简单找规律

    没有任何变换(III变U和删UU操作)之前,I 的个数一定是2^x个(也就是2的整数次幂) 若仅考虑III变U,那么设U的个数为k,I 的个数变为2^x-3*k 再加上删除UU操作,假设我们删除了2* ...

  7. HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6

    现在有一个字符串"MI",这个字符串可以遵循以下规则进行转换: 1.Mx 可以转换成 Mxx ,即 M 之后的所有字符全部复制一遍(MUI –> MUIUI) 2.III 可 ...

  8. MU Puzzle HDU - 4662

    Suppose there are the symbols M, I, and U which can be combined to produce strings of symbols called ...

  9. HDU-4662 MU Puzzle 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 倒推考虑长度就可以了. //STATUS:C++_AC_31MS_240KB #include ...

随机推荐

  1. LeetCode: Sqrt

    Title: Implement int sqrt(int x). Compute and return the square root of x. 思路:这个平方根肯定是在[1,x]之间,所以在这个 ...

  2. 开源的rtsp实现

    开源的rtsp实现                            ============== -- by BeagleTam                                  ...

  3. fzu 1675 The Seventy-seven Problem

    给你长度为 10^5~10^6长度,由数字组成的串 其中有4位不见了 补全该串 使得在该串能整除 77的同时 尽可能大// 先计算出每个 n*10^m 模 77 的循环节 n=0,1,2..,9// ...

  4. 【转】那些不能错过的Xcode插件 -- 不错不错

    原文网址:http://www.cocoachina.com/industry/20130918/7022.html 古人云“工欲善其事必先利其器”,打造一个强大的开发环境,是立即提升自身战斗力的绝佳 ...

  5. HTML5全球普及加速:有望终结iOS与安卓界限【转】

    HTML5或将成为未来移动互联网时代的颠覆者. 5年前,当第一台iPhone诞生时,乔布斯断然拒绝了FlashPlayer,而选择HTML5(新型网页标准)取代Flash的功能.他曾预言,“虽然现阶段 ...

  6. delphi 如何关闭 Unsafe typecast of 和 Unsafe type 的waring

    有时在Delphi使用指针类型的数据,总是提示如下: [Warning] FGroupFeedBack.pas(796): Unsafe typecast of 'Pointer' to 'TObje ...

  7. 利用c#反射实现实体类生成以及数据获取与赋值

    转:http://hi.baidu.com/xyd21c/item/391da2fc8fb351c10dd1c8b8 原有的实体类成员逐个赋值与获取的方法弊端: 1.每次对实体类属性进行赋值时,都要检 ...

  8. HDU 5114 Collision

    Collision Time Limit: 15000/15000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Total ...

  9. 有效处理java异常的三个原则

    Java中异常提供了一种识别及响应错误情况的一致性机制,有效地异常处理能使程序更加健壮.易于调试.异常之所以是一种强大的调试手段,在于其回答了以下三个问题: 什么出了错? 在哪出的错? 为什么出错? ...

  10. IT版孔乙己(转)

    [不要做学究]回忆孔先生IT版 我关于本文评价:看到这篇文章很多人会生出这样的疑问“这明明是在诋毁钻研技术的人嘛?是不是在宣扬技术无用论?”. 初看这篇文章的时候我也是这样的想法,但是逐步才明白这篇文 ...