MU Puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1997    Accepted Submission(s): 787

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

 
代码写得好丑,都要丑哭了T T
U->3I, cnt/2 % 3 == 1 || cnt/2%3 == 2即可。
//2017-08-03
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
char str[N]; int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s", str);
int cnt = ;
bool fg = ;
if (str[] == 'M')
{
for (int j = ; j < strlen(str); j++)
{
if (str[j] == 'I')
cnt++;
else if (str[j] == 'U')
cnt += ;
else if(str[j] == 'M')fg = ;
}
}else{
printf("No\n");
continue;
}
if(fg == ){
printf("No\n");
continue;
}
if (cnt <= )
{
if (cnt == || cnt == )
fg = ;
else
fg = ;
}
else
{
if (cnt % == )
fg = ;
else
{
cnt /= ;
if (cnt % == || cnt % == )
fg = ;
else
fg = ;
}
}
if (fg)
printf("Yes\n");
else
printf("No\n");
} return ;
}

HDU4662(SummerTrainingDay03-B)的更多相关文章

  1. HDU-4662 MU Puzzle 水题

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

  2. HDU4662+无

    把目标中的 U 转化为 I. 又因为 I的个数是有规律的:1 2 4 8 16 ...再结合可以取消 6 12 18 ...个I...得解 #include<string.h> #incl ...

  3. [hdu4662]MU Puzzle(找规律)

    题意:给你一个串MI,按照三种规则1:M后面的部分加倍 2:III->U 3:删去连续的两个UU.看看能否变为给定的串 解题关键:将所有的U转化为I,发现 t+k*6=2^i -> =2^ ...

  4. hdu4662 简单搜索打表

    题意:      给你一个初始串"MI",这个串有三种操作, (1)M后卖弄可以直接复制 ,MI -> MII (2)三个III可以变成一个U,MUIII -> MUU ...

  5. 2013 Multi-University Training Contest 6

    HDU-4655 Cut Pieces 题意:有N个格子能够被涂色,每个格子能够涂1-ai 种颜色,当N=6,涂色方案:112233 认为方案中共有3个颜色块:涂色方案:121212 认为方案中共有6 ...

随机推荐

  1. 拿pyg 的fastdfs分布式文件系统 存储的位置

    http://192.168.25.133/group1/M00/00/00/wKgZhVtW1vqAUpkZAABcxtZsmb0631.png StorageClient1  upload_fil ...

  2. 百度地图sdk---pc端

    <div class="map" style="width: 1196px;height: 500px;margin: 50px auto;"> & ...

  3. POJ 2442(优先队列 k路归并 堆)

    Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...

  4. 使用httpClient模拟http请求

    在很多场景下都需要用到java代码来发送http请求:如和短信后台接口的数据发送,发送数据到微信后台接口中: 这里以apache下的httpClient类来模拟http请求:以get和Post请求为例 ...

  5. 分布式管理GIT命令总结(转载)

    GIT是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  6. POJ 2491

    #include<iostream>#include<stdio.h>#include<string>#define MAXN 400using namespace ...

  7. Spring WebSocket踩坑指南

    Spring WebSocket踩坑指南 本次公司项目中需要在后台与安卓App间建立一个长连接,这里采用了Spring的WebSocket,协议为Stomp. 关于Stomp协议这里就不多介绍了,网上 ...

  8. odoo 开发基础 -- postgresql重新启动、状态查看

    场景描述: 当遇到数据库不能正常访问的时候,我们首先想到的是,查看相关的告警日志,一般先查看系统的日志,然后查看数据库的日志,Linux平台下,postgresql的日志文件存放目录在如下路径: te ...

  9. Shell常见的快捷键

    Ctrl + a - Jump to the start of the lineCtrl + b - Move back a charCtrl + c - Terminate the command ...

  10. Java多线程-Callable的Future返回值的使用

    一般使用线程池执行任务都是调用的execute方法,这个方法定义在Executor接口中: public interface Executor { void execute(Runnable comm ...