HDU4662(SummerTrainingDay03-B)
2024-09-09 03:10:09
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?
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'.
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
MI
MU
Sample Output
Yes
No
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 ;
}
最新文章
- Java当中的反射
- loadrunner --global schedule设置
- yii2整合百度编辑器umeditor
- iOS开发中的4种数据持久化方式【一、属性列表与归档解档】
- Html5文件
- POJ2823 Sliding Window
- json格式不对引起的报错
- 被Play framework狠狠的play了一把
- 可以获取客户端ip的API
- 怒刷DP之 HDU 1176
- MultiSelectListPreference 的使用心得
- ios 工程配置统一增加类的前缀(知识点也只能算知识点)
- python序列化之pickle
- 浏览器桌面通知(notifications)
- aix6.1 openssh安装
- C# 匿名方法和拉姆达表达式
- 《android开发艺术探索》读书笔记(一)--Activity的生命周期和启动模式
- 聊聊 Spring Boot 2.x 那些事儿
- Java:Spring @Transactional工作原理
- Laravel用post提交表单常见的两个错误
热门文章
- day02 基本数据类型与运算符
- 人工智能-机器学习之Selenium(chrome驱动,火狐驱动)
- 10-02 Java 形式参数和返回值的问题深入研究,链式编程
- HuLu机器学习问题与解答系列(1-8)
- 线程中消费者生产者的实例代码(synchronized关键字)
- C# 字符串操作详解
- Mac 安装 Ruby, Rails 运行环境
- 在vue中使用vuex 一个简单的实例
- (Dijkstra)迪杰斯特拉算法-最短路径算法
- PTA (Advanced Level) 1005 Spell It Right