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. js变量提升

    JavaScript的函数定义有个特点,它会先扫描整个函数体的语句,把所有申明的变量“提升”到函数顶部: 'use strict'; function foo() { var x = 'Hello, ...

  2. Spring WebSocket踩坑指南

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

  3. java基本语法三

    1 程序流程控制 流程控制语句是用来控制程序中各语句执行顺序的语句,可以将语句组合完成能完成一定功能的小逻辑模块. 流程控制方式采用结构化程序设计中规定的三种基本流程,即: ①顺序结构: 程序从上到下 ...

  4. (转)contextlib — 上下文管理器工具

    原文:https://pythoncaff.com/docs/pymotw/contextlib-context-manager-tool/95 这是一篇社区协同翻译的文章,你可以点击右边区块信息里的 ...

  5. python实战问题记录

    开发环境搭建 1.安装aiohttp这个异步的http框架失败 提示使用pip更高版本,但是更新之后,还是无法使用.所以,我们采用anaconda中的aiohttp,即打开anaconda,然后进入E ...

  6. 修改vs2012 颜色

    http://bbs.pcbeta.com/viewthread-1265615-1-1.html VS2012的默认深色主题的确让整个IDE看起来很有气场,而且深色的主题保护眼睛,还是蛮不错的. 但 ...

  7. Spring Security OAuth2实现单点登录

    1.概述 在本教程中,我们将讨论如何使用 Spring Security OAuth 和 Spring Boot 实现 SSO(单点登录). 本示例将使用到三个独立应用 一个授权服务器(中央认证机制) ...

  8. mycat ER 分片表

    <table name="order" dataNode="dn$1-32" rule="mod-long"> <chil ...

  9. 复刻smartbits的国产网络测试工具minismb功能特点-如何加载、发送PCAP数据包

    复刻smartbits的网络性能测试工具minismb,是一款专门用于测试智能路由器,网络交换机的性能和稳定性的软硬件相结合的工具.可以通过此以太网测试工具测试任何ip网络设备的端口吞吐率,带宽,并发 ...

  10. <Think Python>中斐波那契使用memo实现的章节

    If you played with the fibonacci function from Section 6.7, you might have noticed thatthe bigger th ...