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? 

InputFirst 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 <= 10 6.Outputn lines, each line is 'Yes' or 'No'.Sample Input

2
MI
MU

Sample Output

Yes
No 所有U都是由I换来的,而U不能再换成I,所以可以讲所有U换成I的数目进行统计,如果符合要求即可
1.相当于I的数目*2
3.相当于I的数目-6
#include <cstdio>
#include <cstring> using namespace std; const int maxn = + ;
char s[maxn];
int p[]; void init(){
p[] = ;
for(int i = ; i < ; i++) p[i] = (p[i-] << );
} bool solve(){
bool ok = ;
int len = strlen(s), i, Mcnt = , Icnt = ;
for(i = ; i < len; i++){
if(s[i] == 'M') Mcnt++;
else if(s[i] == 'I') Icnt++;
else if(s[i] == 'U') Icnt += ;
}
if(Mcnt == && s[] == 'M'){
for(i = ; i >= ; i--) if(p[i] >= Icnt && (p[i] - Icnt) % == ) {
ok = ;
break;
}
}
return ok;
} int main()
{
int n;
init();
scanf("%d", &n);
getchar();
while(n--){
scanf("%s", s);
if(solve()) printf("Yes\n");
else printf("No\n");
}
return ;
}

MU Puzzle HDU - 4662的更多相关文章

  1. hdu 4662 MU Puzzle

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 MU Puzzle Time Limit: 2000/1000 MS (Java/Others) ...

  2. 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 ...

  3. HDU 4662 MU Puzzle:找规律

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

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

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

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

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

  6. HDU 4662 MU Puzzle(找规律)

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

  7. HDU 4662 MU Puzzle 简单找规律

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

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

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

  9. HDU-4662 MU Puzzle 水题

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

随机推荐

  1. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第四天(非原创)

    文章大纲 一.课程介绍二.今日内容介绍三.参考资料下载四.参考文章 一.课程介绍 一共14天课程(1)第一天:电商行业的背景.淘淘商城的介绍.搭建项目工程.Svn的使用.(2)第二天:框架的整合.后台 ...

  2. [POJ1509]Glass Beads 后缀自动机 最小循环串

    题目链接:http://poj.org/problem?id=1509 题目意思就是求循环字符串的最小表示. 我们用字符串S+S建立SAM,然后从root开始走n步,每次尽量选最小的. 由于 SAM ...

  3. npm run dev报错--Error: Cannot find module 'yargs-parser'

    Error: Cannot find module 'yargs-parser'  ---报错不知何解??? 百度了很久没找到方法,是缺少“ yargs-parser ”模块,需要安装一下即可:cnp ...

  4. (二)Redis for 阿里云公网连接

    目录 (一)Redis for Windows正确打开方式 (二)Redis for 阿里云公网连接 (三)Redis for StackExchange.Redis 阿里云目前仅支持内网连接Redi ...

  5. Windows之shortcut

    System key combinations CTRL+ESC: Open Start menu ALT+TAB: Switch between open programs ALT+F4: Quit ...

  6. 物联网初学者智能家居必备迅为iTOP-4412开发板

    更情点击了解:http://www.topeetboard.com 1.  手把手全视频教程: 第一部分:迅为电子开发板入门视频 第二部分:Linux系统编程 第三部分:Itop-4412开发板硬件设 ...

  7. leetcode_357. Count Numbers with Unique Digits

    https://leetcode.com/problems/count-numbers-with-unique-digits/ 给定一个n,计算[0,10^n]中十进制中每一位都不相同的数的数目. c ...

  8. 最好的Sublime Text插件集合

    阅读目录 WebInspector Emmet Git GitGutter & Modific Sublimall AllAutocomplete SublimeREPL DocBlockr ...

  9. cf536b——优先队列的运用

    题目 题目:cf536 B题 题目大意:一个饭店有n种食物,每种食物有对应的价格和数量,然后有m个顾客,每个顾客需要$d_j$份第$t_j$种食物,如果该种食物数量不够,则选其它尽可能便宜的代替(出现 ...

  10. CAD使用SetxDataLong写数据(com接口)

    主要用到函数说明: MxDrawEntity::SetxDataLong 写一个long扩展数据,详细说明如下: 参数 说明 [in] BSTR val 字符串值 szAppName 扩展数据名称 n ...