HDU 4662 MU Puzzle (2013多校6 1008 水题)
MU Puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 134 Accepted Submission(s): 71
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?
Following n lines, each line contains a nonempty string which consists only of letters 'M', 'I' and 'U'.
Total length of all strings <= 106.
MI
MU
No
/*
* Author: kuangbin
* Created Time: 2013/8/8 11:54:08
* File Name: 1008.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
char str[];
const int MAXN = ;
bool dp[MAXN];
bool vis[MAXN];
void init()
{
memset(dp,false,sizeof(dp));
memset(vis,false,sizeof(vis));
dp[] = true;
queue<int>q;
q.push();
vis[] = true;
while(!q.empty())
{
int tmp = q.front();
dp[tmp] = true;
q.pop();
if(tmp == ){dp[] = true;vis[] = true;continue;}
if(tmp >= && !vis[tmp-])
{
q.push(tmp-);
vis[tmp-] = true;
}
tmp *= ;
while(tmp < MAXN)
{
if(vis[tmp])break;
dp[tmp] = true;
if(tmp >= && !vis[tmp-])
{
q.push(tmp-);
vis[tmp-] = true;
}
tmp *= ;
}
}
} int main()
{
int T;
init();
scanf("%d",&T);
while(T--)
{
bool flag = true;
scanf("%s",str);
int len = strlen(str);
if(str[]!='M')
{
printf("No\n");
continue;
}
int cnt = ;
for(int i = ;i < len;i++)
{
if(str[i]=='M')
{
flag = false;
break;
}
if(str[i] =='I')cnt++;
else cnt+= ;
}
if(!flag)
{
printf("No\n");
continue;
}
if(cnt == )
{
printf("Yes\n");
continue;
}
if(cnt% == || cnt% == )printf("No\n");
else printf("Yes\n");
}
return ;
}
HDU 4662 MU Puzzle (2013多校6 1008 水题)的更多相关文章
- HDU 4639 Hehe (2013多校4 1008 水题)
Hehe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6
现在有一个字符串"MI",这个字符串可以遵循以下规则进行转换: 1.Mx 可以转换成 Mxx ,即 M 之后的所有字符全部复制一遍(MUI –> MUIUI) 2.III 可 ...
- hdu 4662 MU Puzzle
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 MU Puzzle Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 4662 MU Puzzle:找规律
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 题意: 初始字符串为"MI". 有三个操作: (1)将'M'之后的所有字符翻 ...
- HDU 4662 MU Puzzle 数论或者水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4662 题目是问目标串能否由MI得到,我们可以逆向思维,目标串能否反过来处理得到MI,所以,首先排除M ...
- 【找规律】HDU 4662——MU Puzzle
来源:点击打开链接 这个题目的来源是人工智能领域MU猜想.比赛的时候也参考了相关资料,可是最后差一点没有把规律推出来. 注意到以下几个性质.第一,MI怎么变换M永远只能在第一位.第二,因为变换时只能在 ...
- HDU 4662 MU Puzzle(找规律)
题意:问是否能把MI通过以下规则转换成给定的字符串s. 1.使M之后的任何字符串加倍(即,将Mx更改为Mxx). 例如:MIU到MIUIU.2.用U替换任何III.例如:MUIIIU至MUUU.3.去 ...
- HDU 4662 MU Puzzle 简单找规律
没有任何变换(III变U和删UU操作)之前,I 的个数一定是2^x个(也就是2的整数次幂) 若仅考虑III变U,那么设U的个数为k,I 的个数变为2^x-3*k 再加上删除UU操作,假设我们删除了2* ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
随机推荐
- [New learn]响应者链机制介绍
1.简介 测试代码库:https://github.com/xufeng79x/EventHandler 响应者链是系统寻找事件相应者的一个路径,他是同touch事件的Hit-testing过程具有 ...
- C++中string类的方法
C++ string类的方法 具体每个方法怎么使用,可以参考相应的链接. 总的链接为http://www.cplusplus.com/reference/string/string/(C++参考文档) ...
- JDBC数据源连接池(3)---Tomcat集成DBCP
此文续<JDBC数据源连接池(2)---C3P0>. Apache Tomcat作为一款JavaWeb服务器,内置了DBCP数据源连接池.在使用中,只要进行相应配置即可. 首先,确保Web ...
- Django Model笔记
常用数据类型 # https://docs.djangoproject.com/en/1.8/ref/models/fields/#field-types BooleanField:布尔类型true/ ...
- linux命令(46):chgrp命令
在lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理.可以使用chgrp指令取变更文件与目录所属群组,这种方式采用群组名称或群组识别码都可以.Chgrp命令就是change group的 ...
- linux命令(45):diff命令
1.命令格式: diff[参数][文件1或目录1][文件2或目录2] 2.命令功能: diff命令能比较单个文件或者目录内容.如果指定比较的是文件,则只有当输入为文本文件时才有效.以逐行的方式,比较文 ...
- C语言写随机数
#include <stdio.h> #include <stdlib.h> #include <time.h> ; unsigned int rand0(); v ...
- 基础平台为第三方应用接入提供oauth2认证接口
oauth2开放认证协议原理及案例分析 http://blog.csdn.net/volcan1987/article/details/7287605 谈谈基于OAuth 2.0的第三方认证 [上篇] ...
- AngularJS之页面跳转Route
1.除了引用AngularJs.js外,还要引用路由JS, "~/Scripts/angularjs/angular-route.js" 2.通过$routeProvider定义路 ...
- 四十六 常用内建模块 itertools
Python的内建模块itertools提供了非常有用的用于操作迭代对象的函数. 首先,我们看看itertools提供的几个“无限”迭代器: >>> import itertools ...