zoj-3983

Crusaders Quest

Time Limit: 1 Second       Memory Limit: 65536 KB

Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the game world, and the only hope for your kingdom is to save the Goddesses so that they can unleash their power to fight against the witch.

In order to save the game world, you need to choose three heroes to fight for victory and use their skills wisely. Nine skill blocks of three different types (three blocks per type) will be presented at the bottom of the screen. If  () consecutive blocks are of the same type, you can tap on them and eliminate them, thus triggering the powerful skill they represent. After the elimination, the blocks to their left will be connected with the blocks to their right. Moreover, if  consecutive blocks of the same type are eliminated, the powerful skill they unleash will be upgraded to a super skill, which is the most powerful skill of all.

DreamGrid is a newbie in this game, and he wants to trigger the super skill as many times as he can. Given nine skill blocks satisfying the description above, please help DreamGrid calculate the maximum number of times he can trigger the super skill.

Input

There are multiple test cases. The first line of input contains an integer  (about 50), indicating the number of test cases. For each test case:

The first line contains a string  () consisting of three 'g's, three 'a's and three 'o's, representing the nine skill blocks of three different types. Each type of character represents one type of skill block.

Output

For each test case, output an integer denoting the maximum number of times DreamGrid can trigger the super skill.

Sample Input
7
gggaaaooo
aaoogggoa
googgaaao
agogaooag
goooggaaa
gogogoaaa
gaogaogao
Sample Output
3
3
2
1
3
2
1
Hint

For the first sample test case, DreamGrid can first eliminate "aaa" (one super skill triggered), thus changing the skill blocks to "gggooo". He can then eliminate "ggg" (another super skill triggered) and finally eliminate "ooo" (a third super skill triggered). So the answer is 3.

For the second sample test case, DreamGrid can first eliminate "ggg" (one super skill triggered), thus changing the skill blocks to "aaoooa". He can then eliminate "ooo" (another super skill triggered) and finally eliminate "aaa" (a third super skill triggered). So the answer is also 3.

For the third sample test case, DreamGrid can first eliminate "aaa" (one super skill triggered), thus changing the skill blocks to "googgo". He can then eliminate "oo" to obtain "gggo", and eliminate "ggg" (another super skill triggered) to obtain "o". So the answer is 2. It is easy to prove that he cannot trigger the super skill three times under this arrangement of skill blocks.


Author:  DAI, Longao

Source: The 2017 China Collegiate Programming Contest, Qinhuangdao Site

题意:相当于消消乐。给你一个字符串长度为9,若3的相同的字符串连在一起则是一个无敌技能,消去一些字符,两边的字符串

会拼接起来。求消去字符串后,有多少个无敌的技能。

解析:最大3,最小为1.   消的情况有6种gao,goa,ago.......等。比如,gao 消的情况就是第一次先消把g字符消掉,第二次把a消掉,这时候肯定只剩下有3个相同的字符,所以说它最小为1.

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<queue>
using namespace std;

int f(char s[],char a,char b,char c)
{
	
	int ans=0,cnt=0;
	int pos[3];
	bool flag=false;
	for(int i=0; i<9; i++)
	{//printf("****\n");
		if(s[i]==a)pos[cnt++]=i;
	}
	for(int i=2; i<9; i++)
	{
		if(s[i]==s[i-2]&&s[i-1]==s[i]&&s[i]==a)
		{
			flag=true;
			break;
		}
	}
	if(flag)ans++;
	flag=false;
	
	cnt=0;
	char temp[10];
	for(int i=0; i<9; i++)
	{
		if(i!=pos[0]&&i!=pos[1]&&i!=pos[2])
		temp[cnt++]=s[i];
	}
	
	cnt=0;
	for(int i=0; i<9; i++)
	{
		if(temp[i]==b)pos[cnt++]=i;
	}
	for(int i=2; i<9; i++)
	{
		if(temp[i]==temp[i-2]&&temp[i-1]==temp[i]&&temp[i]==b)
		{
			flag=true;
			break;
		}
	}
	if(flag)ans++;flag=false;
	
	cnt=0;
	char tempp[10];
	for(int i=0; i<9; i++)
	{
		if(i!=pos[0]&&i!=pos[1]&&i!=pos[2])
		tempp[cnt++]=temp[i];
	}
	for(int i=2; i<9; i++)
	{
		if(tempp[i]==tempp[i-2]&&tempp[i-1]==tempp[i]&&tempp[i]==c)
		{
			flag=true;
			break;
		}
	}
	if(flag)ans++;
	return ans;
}


int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		getchar();
		char s[10];
		scanf("%s",s);
		int a=f(s,'g','a','o');//printf("****\n");
		int b=f(s,'g','o','a');
		int c=f(s,'a','o','g');
		int x=f(s,'a','g','o');
		int y=f(s,'o','g','a');
		int z=f(s,'o','a','g');
		int p=max(a,b);
		int q=max(x,y);
		int ans=max(max(p,q),max(c,z));
		printf("%d\n",ans);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值