博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU4662(SummerTrainingDay03-B)
阅读量:5165 次
发布时间:2019-06-13

本文共 2345 字,大约阅读时间需要 7 分钟。

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 <= 10
6.
 

 

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 
#include
#include
#include
using namespace std;const int N = 1000010;char str[N];int main(){ int T; scanf("%d", &T); while (T--) { scanf("%s", str); int cnt = 0; bool fg = 1; if (str[0] == 'M') { for (int j = 1; j < strlen(str); j++) { if (str[j] == 'I') cnt++; else if (str[j] == 'U') cnt += 3; else if(str[j] == 'M')fg = 0; } }else{ printf("No\n"); continue; } if(fg == 0){ printf("No\n"); continue; } if (cnt <= 4) { if (cnt == 3 || cnt == 0) fg = 0; else fg = 1; } else { if (cnt % 2 == 1) fg = 0; else { cnt /= 2; if (cnt % 3 == 1 || cnt % 3 == 2) fg = 1; else fg = 0; } } if (fg) printf("Yes\n"); else printf("No\n"); } return 0;}

 

转载于:https://www.cnblogs.com/Penn000/p/7281907.html

你可能感兴趣的文章
.NET:CLR via C# Assembly Loading
查看>>
wed开发基础--练习题
查看>>
CentOS安装rar及用法
查看>>
TYVJ-P1864 守卫者的挑战 题解
查看>>
Jzoj5455【NOIP2017提高A组冲刺11.6】拆网线
查看>>
特定字符序列的判断(1028)
查看>>
记一次报错信息
查看>>
判断数组内是否有几个元素之和等于m
查看>>
RestAssured接口自动化测试之基础方法
查看>>
华为面试
查看>>
平衡二叉树(AVL Tree)
查看>>
【BZOJ3295】[Cqoi2011]动态逆序对 cdq分治
查看>>
【CF799E】Aquarium decoration 线段树
查看>>
大运飞天 鲲鹏展翅
查看>>
从ECMA到W3C
查看>>
软件工程--第十六周学习进度
查看>>
yii2 ActiveRecord多表关联以及多表关联搜索的实现
查看>>
搜狗输入法安装--ubuntu
查看>>
ps/2接口键盘的输入及显示
查看>>
Swift———a Glance(极客学院)笔记
查看>>