hdu 4622 **
2015-07-04 23:27
204 查看
题意: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?
首先全部转化为I
可以发现,能被6整除或者i的个数是奇数且不为1的不可以,其他都可以
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?
首先全部转化为I
可以发现,能被6整除或者i的个数是奇数且不为1的不可以,其他都可以
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 const int INF=0x3f3f3f3f; const double eps=1e-5; typedef long long ll; #define cl(a) memset(a,0,sizeof(a)) #define ts printf("*****\n"); const int MAXN=1005055; int n,m,tt; char s[MAXN]; int main() { int i,j,k; #ifndef ONLINE_JUDGE freopen("1.in","r",stdin); #endif scanf("%d",&tt); while(tt--) { scanf("%s",s); if(s[0]!='M') { printf("No\n"); continue; } int cnt=0; bool flag=1; int len=strlen(s); for(i=1;i<len;i++) { if(s[i]=='M') { flag=0; break; } if(s[i]=='I') cnt++; else cnt+=3; } if(((cnt%6==0)||cnt%2==1&&cnt!=1)||!flag) { printf("No\n"); } else printf("Yes\n"); } }
相关文章推荐
- HDU 1202 The cacluation of GPA
- 电路分析学习感想
- Linux文件管理
- 程序员工作中会遭遇的天花板 工作中不由你控制的一些地方(转)
- 关于linux 添加新的硬盘
- SQL Server 2008 R2 安装出错:Could not open key
- ECshop网点程序优化-后台添加类目自动选择上次父类目并计算Sort Order
- SecureCRT连接本地虚拟机中linux
- Java回调的一种简易实现
- A ResourcePool could not acquire a resource from its primary factory or source.
- 成不了天才,但为何也没成"人材"?(转)
- 解读提升百度权重-刷百度指数的方法
- 装在u盘的linux
- shell中的文件处理
- HDU 1106排序
- 我的第一份网站SEO优化方案是怎样炼成的?
- ECshop网点程序优化-自动生成类目页Keywords、Desciption Meta
- Vbs脚本定时判断及启动tomcat服务
- 3个开源的 Python Shell
- 为什么我不推荐大家去外包公司(转)