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贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
随机推荐
- 网络I/O模型--07Netty基础
Netty 是由 JBOSS 提供的一个 Java 开源框架. Netty 提供异步的.事件驱动的网络应用程序框架和工具 ,用以快速开发高性能 . 高可靠性的网络服务器和客户端程序. Net ...
- 重要BLOG
Cloud http://www.cnblogs.com/CloudMan6/tag/OpenStack/ 算法基础 http://www.cnblogs.com/ECJTUACM-873284962 ...
- Android Service不能再详细的教程
这篇包含了: Service后台服务.前台服务.IntentService.跨进程服务.无障碍服务.系统服务 几乎所有Android Service相关的东西. 前言 作为四大组件之一的Service ...
- HSQL结合润乾报表同步部署问题
1 . 问题概述 中国登记结算公司为了验证报表模型和附带的样例[内建的不算],都是需要连接携带的DEMO数据源才能够运行, 应用程序[润乾报表]需要部署到UNIX服务器上, DEMO自带的HSQ ...
- redis 集群目标、集群查看、配置方法及过程、哨兵配置启动
集群目标 主从复制,读写分离:故障切换(通过哨兵实现) 查看集群状态 info replication 配置方法 只设置从数据库就可以了:最佳实践,在主数据库配置masterauth <mast ...
- Eclipse 下载、安装、取消自动更新、设置编码、关联Tomcat
1.下载 (1)安装jdk 如果进行web开发,下载java se 版本的jdk即可,不需要像安装 java se 一样安装java ee(里面大多是接口和抽象类).关于java ee的依赖问题有两种 ...
- 修改spfile位置
虽然很多地方不建议这么做,可是有HA.oracle软件建在本地盘的情况下,如果spfile放在dbs下,会导致每次修改spfile都要去手动copy到备机上,这是很麻烦的一件事情,所以我把spflie ...
- MongoDB数据库安装及配置环境(windows10系统)
windows10系统下MongoDB的安装及环境配置: MongoDB的安装 下载地址: https://www.mongodb.com/download-center (这是windows10环境 ...
- zabbix系列之六——安装后配置二Items
https://www.zabbix.com/documentation/3.4/manual/config/items/itemtypes/snmp 1Items 1.1creating items ...
- [转载]敏感词过滤,PHP实现的Trie树
原文地址:http://blog.11034.org/2012-07/trie_in_php.html 项目需求,要做敏感词过滤,对于敏感词本身就是一个CRUD的模块很简单,比较麻烦的就是对各种输入的 ...