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. python 数据类型一 (重点是字符串的各种操作)

    一.python基本数据类型 1,int,整数,主要用来进行数学运算 2,bool,布尔类型,判断真假,True,False 3,str,字符串,可以保存少量数据并进行相应的操作(未来使用频率最高的一 ...

  2. 【spring cloud】服务启动后正常,但是无法上线,一直处于down状态

    spring cloud eureka 如果出现某个应用实例 down(1), 说明 spring admin 健康检测没有通过导致 eureka 注册中心不会把这个实例从列表中删除掉. 这样所有使用 ...

  3. jQuery的ajax的post请求json格式无法上传空数组

    问题描述:在和后端对接时,使用jquery的ajax的post方式向后端传递一序列约定好格式的对象数组.遇到了一个现象:如果对象中的数组是空数组,那么在请求参数中是不会出现的. 以下是数据的对比:   ...

  4. Spring Integration Zip不安全解压(CVE-2018-1261)漏洞复现

    不敢说分析,还是太菜了,多学习. 文章来源: 猎户安全实验室 存在漏洞的源码下载地址:https://github.com/spring-projects/spring-integration-ext ...

  5. postgresql-hdd,ssd,效率

    既有ssd又有hdd是将数据存储到ssd还是将索引存储到ssd的效率更高呢? 一种说法是索引是随机扫描,将索引放入ssd效率会增高, 一种说法是将数据放入ssd效率更高   最好的情况是将数据和索引都 ...

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

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

  7. 网络Socket编程UDP协议例子

    服务端代码 public class UDPChatServer { //通讯端口 private Integer port=8000; //数据报文的通讯通道对象 private DatagramC ...

  8. (转)AIX7.1安装Nginx 1.13的方法

    原文:https://blog.csdn.net/lvshaorong/article/details/79401860 https://blog.csdn.net/lvshaorong/articl ...

  9. JavaScript -- Window-弹出窗口

    -----033-Window-弹出窗口.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=& ...

  10. tsung压力测试——Tsung测试统计报告说明【转】

    1.主要统计信息 Tsung统计数据是平均每十秒重置一次,所以这里的响应时间(连接.请求.页面.会话)是指每十秒的平均响应时间: connect: 表示 每个连接持续时间: Hightest 10se ...