694
技術社區[雲棲]
hdu 4662 MU Puzzle 模擬
模擬題,易知將所有U換成I,補全所有刪去的U,應為2的冪,又因為每次刪去2個U,即6個I,所以對6取模,發現餘數隻有2和4,所以如果餘數為2,4則必為yes。
注意開頭不為M和中間有M的情況
/* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #define INF 1E9 using namespace std; int main() { int T; char s[1000005]; scanf("%d",&T); while(T--) { scanf("%s",s); int i,j=0,len=strlen(s); if(s[0]=='M') for(i=1,j=0;i<len;i++) { if(s[i]=='U') j+=3; else if(s[i]=='I')j++; else {j=0;break;} } printf("%s\n",j%6!=2&&j%6!=4&&j!=1?"No":"Yes"); } }
最後更新:2017-04-03 15:21:43