C - Crusaders Quest

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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 \(k\) (\(k \ge 1\)) 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 \(k=3\) 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 \(T\) (about 50), indicating the number of test cases. For each test case:

The first line contains a string \(s\) (\(|s| = 9\)) 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.

题意
给我们一个字符串 其中只有a,o,g 
当三个相同字符连在一起时释放大技能
我们可以消除任意连续数量的字符 
问我们最大的释放大技能的数量是多少
 
分析:
要释放最多的技能
那么就只有6种消除的顺序,a,g,o的全排列
比如对于第一种a g o
先找到字符串中a的位置,有连续的三个a就sum++
然后消去a
然后再在串中找g
有连续的g就sum++
遍历每种a g o的全排列
找到sum的最大值
 
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<math.h>
using namespace std;
#define max_v 105
#define INF 9999999999
int s[][]={ {'a','g','o'},
{'a','o','g'},
{'g','a','o'},
{'g','o','a'},
{'o','a','g'},
{'o','g','a'}};//消除顺序
int main()
{
int t;
char str[];
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
int ans=;
for(int k=;k<;k++)
{
char a[];
int y=;
for(int i=;i<;i++)
{
if(str[i]==s[k][])
a[y++]=i;
}
int sum=;
int flag=;
for(int i=;i<;i++)
{
if(str[i]==str[i+]&&str[i+]==str[i+]&&str[i+]==s[k][])
{
flag=;
break;
}
}
if(flag)
sum++; char temp[];
y=;
for(int i=;i<;i++)
{
if(i!=a[]&&i!=a[]&&i!=a[])
temp[y++]=str[i];
} flag=;
for(int i=;i<;i++)
{
if(temp[i]==temp[i+]&&temp[i+]==temp[i+]&&temp[i+]==s[k][])
{
flag=;
break;
}
}
if(flag)
sum++; ans=max(ans,sum);
}
printf("%d\n",ans);
}
return ;
}
/*
题意
给我们一个字符串 其中只有a,o,g 
当三个相同字符连在一起时释放大技能
我们可以消除任意连续数量的字符 
问我们最大的释放大技能的数量是多少 分析:
要释放最多的技能
那么就只有6种消除的顺序,a,g,o的全排列
比如对于第一种a g o
先找到字符串中a的位置,有连续的三个a就sum++
然后消去a
然后再在串中找g
有连续的g就sum++
遍历每种a g o的全排列
找到sum的最大值
*/

ZOJ 3983 Crusaders Quest(思维题)的更多相关文章

  1. zoj 3983 Crusaders Quest 思维+枚举

    题目链接 这道题意思是: 给你一个长度为9的字符串,且只有3个a.3个g.3个o 问,你可以选择删除一段连续的串或者单个的字符也可以不删,最多会出现几个三子相连的子串 比如:agoagoago只有将两 ...

  2. ZOJ - 3983 - Crusaders Quest(思维 + 暴力)

    题意: 给出一个字符串,长度为9,包含三种各三个字母"a","g","o",如果一次消除连续三个一样的分数+1,消完自动向左补齐 其中可以消 ...

  3. ZOJ 3983 - Crusaders Quest - [DFS]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3983 题意: 给出一个长度为 $9$ 的字符串 $s$,且 $s ...

  4. zoj 3778 Talented Chef(思维题)

    题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...

  5. ZOJ 4060 - Flippy Sequence - [思维题][2018 ACM-ICPC Asia Qingdao Regional Problem C]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060 题意: 给出两个 $0,1$ 字符串 $S,T$,现在你有 ...

  6. ZOJ Saddle Point 数学思维题

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564   根据它的定义是行最小,列最大. 可以证明鞍点是唯一的. ...

  7. ZOJ 3829 贪心 思维题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...

  8. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  9. 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)

    思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...

随机推荐

  1. 高斯消元与期望DP

    高斯消元可以解决一系列DP序混乱的无向图上(期望)DP DP序 DP序是一道DP的所有状态的一个排列,使状态x所需的所有前置状态都位于状态x前: (通俗的说,在一个状态转移方程中‘=’左侧的状态应该在 ...

  2. 超级简单的jquery轮播图demo

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Ubuntu-16.04-Desktop +Hadoop2.7.5+Eclipse-Neon的云计算开发环境的搭建(伪分布式方式)

    主控终端 主机名 ubuntuhadoop.smartmap.com IP 192.168.1.60 Subnet mask 255.255.255.0 Gateway 192.168.1.1 DNS ...

  4. vue + skyline 搭建 一个开发环境

    1.之前用的是ext +  skyline搭建环境 ,正好最近是做前端的事情,有时间用vue + skyline 搭建一个三维场景 2.准备vue 2.x  ,UI 用的是iview 和element ...

  5. String path = request.getContextPath

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

  6. Android上实现视频录制

    首先,我们肯定要用到摄像头,因此需要在Manifest文件中声明使用权限: <uses-permission android:name="android.permission.CAME ...

  7. Hive常用配置

    1.配置hive在HDFS上的根目录位置 <property> <name>hive.metastore.warehouse.dir</name> <valu ...

  8. Windows 安装 python MySQLdb模块

    pip install wheel 去这个网站查找whl格式的MYSQL-python http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python ...

  9. zabbix使用问题

    1中文乱码 https://www.linuxidc.com/Linux/2017-08/146162.htm 软件 说明 备注 zabbix 3.4.7 操作系统 Centos7 问题描述:图表内容 ...

  10. 使用eclipse遇到的unable to install breakpoint的问题

    调试一个tomcat工程,设置好断点,启动工程,结果出现了下面的错误: 继续运行,再进入断点之前,还会再度提示,但是最终会命中断点. 使用CGLIB查找关键字,了解到CGLIB是一个AOP的拦截库,想 ...