现在的位置: 首页 > 综合 > 正文

HDU4662+无

2013年09月04日 ⁄ 综合 ⁄ 共 573字 ⁄ 字号 评论关闭

把目标中的 U 转化为 I。

又因为 I的个数是有规律的:1 2 4 8 16 。。。再结合可以取消 6 12 18 。。。个I。。。得解

#include<string.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 1000000+5;
map<int,int>mp;
void init(){
	mp.clear();
	int tt = 1;
	while( tt<maxn ){
		mp[ tt ] = 1;
		int tmp = tt;
		while( mp[tt]==1&&tmp>=6 ){
			mp[ tmp ] = 1;
			tmp -= 6;
		} 
		tt *= 2; 
	}
}
int main(){
	int n;
	init();
	scanf("%d",&n);
	while( n-- ){
		string s;
		cin>>s;
		int ans = 0;
		int len = s.size();
		int ans2 = 0;
		bool f = true;
		for( int i=1;i<len;i++ ){
			if( s[i]=='I' ){
				ans++;
			}
			else if( s[i]=='U' ){
				ans += 3;
			}
			else f = false ;
		}
		if( mp[ans]==1&&f==true&&s[0]=='M' ) puts("Yes");
		else puts("No");
	}
	return 0;
}

抱歉!评论已关闭.