题目链接: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. Window 下 VFW 视频采集与显示

    引言 经过几天的努力终于将VFW视频采集与显示功能完整实现了,不得不说网上对这方面完整的详细讲解文章是在太少了.所以就要本人来好好总结一下让后来者不再像我一样折腾好久.在本文中我将详细讲解VFW视频采 ...

  2. dbms_stats.gather_table_stats与analyze table 的区别[转贴]

    Analyze StatementThe ANALYZE statement can be used to gather statistics for a specific table, index ...

  3. 【转】linux中waitpid及wait的用法

    原文网址:http://www.2cto.com/os/201203/124851.html wait(等待子进程中断或结束) 表头文件      #include<sys/types.h> ...

  4. 转载:看c++ primer 学习心得

    学习C++ Primer时遇到的问题及解释 chenm91 感觉: l          啰嗦有时会掩盖主题:这本书确实有些啰嗦,比如在讲函数重载的时候,讲了太长一大段(有两节是打了*号的,看还是不看 ...

  5. webdriver(python)学习笔记二

    自己开始一个脚本开始学习: # coding = utf-8 from selenium import webdriver browser = webdriver.Firefox() browser. ...

  6. [原创]Android应用 - YE启动器APP(YeLauncherApp)

      支持解冻.冻结APP 支持在本APP列表隐藏指定APP 支持检测系统核心APP,防止误点冻结导致手机变砖 支持清理APP缓存 支持强制停止APP Apk文件仅仅47KB 自用.开源 类似APP:A ...

  7. C#汉字转换拼音技术详解

    C#汉字转换拼音技术详解(高性能) 下面将源代码贴出.public static class ChineseToPinYin           {               private sta ...

  8. C语言的代码内存布局

    由以下3个部分组成: 1)BSS 段 BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文Block Started by Symbol的简称.BSS ...

  9. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  10. sublime text 2使用经验

    1. Package Control 安装代码: import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.instal ...