hdu 4662 MU Puzzle
来源:互联网 发布:linux cdn 编辑:程序博客网 时间:2024/04/29 14:15
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'.
Total length of all strings <= 106.
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
2MIMU
Sample Output
YesNo1、Mx -> Mxx2、III -> U3、UU -> 空问MI 能否进过上面操作转化成 读入的字符串。重点是怎么推式子1、M前面的不能有字母。2、只能有一个M3、操作一只能得到 2^n个I (n > 0)4、可以消去6个I.然后得到一个公式 2^n - 6 * m = sum; (sum 表示读入的字符串中I的个数);#include<iostream>#include<cstring>using namespace std;char s[1000001];int main(){ int n,j,u,i; cin>>n; while(n--) { cin>>s; u=i=0; if(s[0]!='M'||s[1]==0) { cout<<"No"<<endl; } else if(strcmp(s,"MI")==0) { cout<<"Yes"<<endl; } else if(strcmp(s,"MU")==0) { cout<<"No"<<endl; } else { for(j=1;s[j];j++) { if(s[j]=='U') u++; else if(s[j]=='I') i++; if(s[j]=='M') { cout<<"No"<<endl; break; } } if(s[j]) { continue; } if((u*3+i)%2==0&&i>0&&(u*3+i)%3!=0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } return 0;}
0 0
- hdu 4662 MU Puzzle
- HDU 4662 MU Puzzle
- HDU 4662 MU Puzzle
- HDU-4662 MU puzzle
- HDU 4662 MU Puzzle
- hdu 4662 MU Puzzle
- hdu 4662 MU Puzzle
- HDU 4662 MU Puzzle
- HDU 4662 MU Puzzle (水题)
- hdu 4662 MU Puzzle 模拟
- hdu 4662 MU Puzzle 余数
- hdu 4662 MU Puzzle(水)
- HDU 4662 MU Puzzle(找规律)
- hdu 4662 MU Puzzle 多校第六场
- 2013 多校第六场 hdu 4662 MU Puzzle
- hdu 4662 MU Puzzle 13多校第六场
- HDU 4662 MU Puzzle 多校最水的一题
- HDU 1381 Crazy Search(HASH) 4662 MU Puzzle
- C++ 如何从string中删除一个字符?
- SQL group by的困惑
- Binary Tree Maximum Path Sum
- 链表学习笔记
- 三大主流工作流引擎技术分析与市场预测
- hdu 4662 MU Puzzle
- 两个程序员的泰国普吉岛之行
- 初识HTML
- struts2 url重写
- TCP连接的建立与终止
- 鸽巢排序
- QT皮肤(QSS)编程
- Jquery-validate插件实现表单格式验证
- 珠排序