ZOJ 3983 Crusaders Quest(思维题)
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 () 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.
给我们一个字符串 其中只有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[6][3]={ {'a','g','o'}, {'a','o','g'}, {'g','a','o'}, {'g','o','a'}, {'o','a','g'}, {'o','g','a'}};//消除顺序 int main() { int t; char str[10]; scanf("%d",&t); while(t--) { scanf("%s",str); int ans=0; for(int k=0;k<6;k++) { char a[3]; int y=0; for(int i=0;i<9;i++) { if(str[i]==s[k][0]) a[y++]=i; } int sum=1; int flag=0; for(int i=0;i<7;i++) { if(str[i]==str[i+1]&&str[i+1]==str[i+2]&&str[i+2]==s[k][0]) { flag=1; break; } } if(flag) sum++; char temp[10]; y=0; for(int i=0;i<9;i++) { if(i!=a[0]&&i!=a[1]&&i!=a[2]) temp[y++]=str[i]; } flag=0; for(int i=0;i<6;i++) { if(temp[i]==temp[i+1]&&temp[i+1]==temp[i+2]&&temp[i+2]==s[k][1]) { flag=1; break; } } if(flag) sum++; ans=max(ans,sum); } printf("%d\n",ans); } return 0; } /* 题意 给我们一个字符串 其中只有a,o,g 当三个相同字符连在一起时释放大技能 我们可以消除任意连续数量的字符 问我们最大的释放大技能的数量是多少 分析: 要释放最多的技能 那么就只有6种消除的顺序,a,g,o的全排列 比如对于第一种a g o 先找到字符串中a的位置,有连续的三个a就sum++ 然后消去a 然后再在串中找g 有连续的g就sum++ 遍历每种a g o的全排列 找到sum的最大值 */
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南