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. PHP通用分页类page.php[仿google分页]

    <?php /** ** 通用php分页类.(仿Google样式) ** 只需提供记录总数与每页显示数两个参数.(已附详细使用说明..) ** 无需指定URL,链接由程序生成.方便用于检索结果分 ...

  2. 在Eclipse中指定JDK

    1.Windows下的Eclipse中的eclipse.ini -startup plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540 ...

  3. RESTful API的十个最佳实践

    WebAPI在过去几年里非常的盛行,我们很多以往的技术手段都慢慢的转换为使用WebAPI来开发,因为它的语法简单规范化,以及轻量级等特点,这种方式收到了广泛的推崇. 通常我们使用RESTFul(Rep ...

  4. Android获取SD卡路径及SDCard内存的方法

    这篇文章主要介绍了Android获取SD卡路径及SDCard内存的方法,较为详细的分析了Android针对SD卡操作所涉及的类及其具体函数功能,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了A ...

  5. 可执行文件patch技术&&持续更新

    前言 在ctf比赛中, 有时我们需要对可执行文件进行patch, 或者在植入后门时,patch也是常用的手段.不过手工patch比较麻烦,下面介绍几个工具.本文介绍遇到的各种技术,不断更新. ELF ...

  6. Ubuntu 16.04 小飞机启动失败

    好长时间没用小飞机了,今天打开发现,无法启动了. 查看了日志: Initialising ciphers... AES-256/CFB (aes-256-cfb) initialised. Runni ...

  7. CCSUOJ评测系统——第二次scrum冲刺

    1.小组成员 舒 溢 许嘉荣 唐 浩 黄欣欣 廖帅元 2.第二次冲刺任务安排 对HUSTOJ数据库进行分析 序号 表名 作用 备注 1 compileinfo 记录编译错误的记录 2 contest ...

  8. ubuntu安装zeromq

    官网地址:http://zeromq.org/ ubuntu下zmq安装 (1)下载:wget http://download.zeromq.org/zeromq-4.1.4.tar.gz (2)解压 ...

  9. WEB API 支持多种端的后台

    一套代码,支持多种平台 1. 支持web 可以js获取webapi的数据源.利用mvvm组织展现在html上. 2.支持安卓. post方法,安卓获取webapi的数据.

  10. 记开发个人图书收藏清单小程序开发(七)DB设计

    前面的书房初始化的前端信息已经完善,所以现在开始实现DB的Script部分. 新增Action:Shelf_Init.sql svc.sql CREATE SCHEMA [svc] AUTHORIZA ...