ZOJ 3983 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(思维题)的更多相关文章
- zoj 3983 Crusaders Quest 思维+枚举
题目链接 这道题意思是: 给你一个长度为9的字符串,且只有3个a.3个g.3个o 问,你可以选择删除一段连续的串或者单个的字符也可以不删,最多会出现几个三子相连的子串 比如:agoagoago只有将两 ...
- ZOJ - 3983 - Crusaders Quest(思维 + 暴力)
题意: 给出一个字符串,长度为9,包含三种各三个字母"a","g","o",如果一次消除连续三个一样的分数+1,消完自动向左补齐 其中可以消 ...
- ZOJ 3983 - Crusaders Quest - [DFS]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3983 题意: 给出一个长度为 $9$ 的字符串 $s$,且 $s ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- 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$,现在你有 ...
- ZOJ Saddle Point 数学思维题
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5564 根据它的定义是行最小,列最大. 可以证明鞍点是唯一的. ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
随机推荐
- navicat 批量插入 测试数据
1. 前言 遇到线上大sql执行较慢, 10s+, 做优化改进时,首先想到的是在本地造出一个类似的库环境,先本地实验. 然后往表中创建大量数据... 2. 方案 利用mysql函数来插入大量数据 代码 ...
- Eclipse工程 导入 Android Studio
最近Eclipse好多项目转Android Studio 百度翻看好多文章 这篇不错 特纪录下 地址:http://www.cnblogs.com/bluestorm/p/3757402.html 一 ...
- overload与override的区别
override(重写,覆盖) 1.方法名.参数.返回值相同. 2.子类方法不能缩小父类方法的访问权限. 3.子类方法不能抛出比父类方法更多的异常(但子类方法可以不抛出异常). 4.存在于父类和子类之 ...
- 构建微服务:快速搭建Spring Boot项目
Spring Boot简介: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...
- clipChildren属性
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- <![CDATA[文本内容]]>
DTD中的属性类型 全名:character data 在标记CDATA下,所有的标记.实体引用都被忽略,而被XML处理程序一视同仁地当做字符数据看待, CDATA的形式如下: <[CDATA[ ...
- Android UI组件----自定义ListView实现动态刷新
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- jenkins集成caliper"
1.jenkins安装caliper-ci插件(Caliper CI Plugin) 2.编写microbench 最简便的办法就是作为单元测试来跑(这样就不用在jenkins里配置跑microben ...
- 数据契约(DataContract)里的DataMember特性
数据契约(DataContract) 服务契约定义了远程访问对象和可供调用的方法,数据契约则是服务端和客户端之间要传送的自定义数据类型. 一旦声明一个类型为DataContract,那么该类型就可 ...
- 使用 CLI 创建 Azure VM 的自定义映像
自定义映像类似于应用商店映像,不同的是自定义映像的创建者是你自己. 自定义映像可用于启动配置,例如预加载应用程序.应用程序配置和其他 OS 配置. 在本教程中,你将创建自己的 Azure 虚拟机自定义 ...