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. webapp开发学习--Ionic+Cordova 环境搭建

    我们看 Ionic 能给我们提供什么? 一个样式库,你可以使用它来装饰你的HTML网页 ,看起来 想 移动程序的界面,什么header .content.footer.grid.list.这貌似没什么 ...

  2. zTree树形控件讲解

    由于截图时间距离有些长,找不到原文出处,如有侵权请联系删除.

  3. Android学习笔记(十四) Handler理论补充

    一.如何下载Android源码 在SDK Manager中选中Sources for Android SDK. 二.ThreadLocal初步介绍 1)执行ThreadLocal对象(static f ...

  4. Java快速读取大文件

    Java快速读取大文件 最近公司服务器监控系统需要做一个东西来分析Java应用程序的日志. 第一步探索: 首先我想到的是使用RandomAccessFile,因为他可以很方便的去获取和设置文件指针,下 ...

  5. 数据库系统概论(1)——Chap. 1 Introduction

    数据库系统概论--Introduction 一.数据库的4个基本概念 数据(data):数据是数据库中存储的基本单位.我们把描述事物的符号记录称为数据.数据和关于数据的解释是不可分的,数据的含义称为数 ...

  6. splice用法解析

    splice()方法算是最强大的数组方法了,它有很多种用法,主要用于删除指定位置的数组项,在指定的位置插入数组项,在指定位置替换数组项,slpice()方法始终都会返回一个数组,该数组包括从原始数组中 ...

  7. CSS 实现斑马条纹

    Part.1 linear-gradient() linear-gradient() 函数用于创建一个线性渐变的 "图像".为了创建一个线性渐变,你需要设置一个起始点和一个方向(指 ...

  8. ubuntu 12.04 配置iscsi共享及挂载iscsi共享

    一.配置ubuntu 下iscsi下的target 1.配置iscsi-target: sudo apt-get install iscsi* 2.配置一个简单的iscsi target: iscsi ...

  9. HTML5页面直接调用百度地图API,获取当前位置,直接导航目的地

    <!DOCTYPE html> <html lang="zh-cmn-Hans"> <meta charset="UTF-8"&g ...

  10. 牛客网提高组第二场---solution

    T1 方差 根据题目要求将式子先写出来注意下面式子中的 $n$ 全部都是 $n-1$$$\begin{aligned}ans&=n^2\times \frac{1}{n}\times \sum ...