2017 CCPC 秦皇岛 & ZOJ 3983 - Crusaders Quest
2017-12-19 23:21
435 查看
Crusaders Quest
Time Limit: 1 Second Memory Limit: 65536 KB
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
4000
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.
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.
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.
题意:
类似消消乐的游戏,问你最多能连续消除3个的操作能有几个。
POINT:
反正就3个字母,遍历这3个字母的消除顺序。
记录每个字母的最左和最右。
消除有3个就ans++。每次消除把最左到最右的字符串全部消除(因为要让他们连续)
重复操作。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#
using namespace std;
const int maxn = 1e2+10;
int l[4],r[4];
int num[4];
void doit(char s[],char a1,char a2,char a3)
{
memset(num,0,sizeof num);
memset(l,-1,sizeof l);
memset(r,-1,sizeof r);
int ll=strlen(s);
for(int i=0;i<ll;i++){
if(s[i]==a1&&l[1]==-1) l[1]=i;
if(s[i]==a2&&l[2]==-1) l[2]=i;
if(s[i]==a3&&l[3]==-1) l[3]=i;
if(s[i]==a1) r[1]=i,num[1]++;
if(s[i]==a2) r[2]=i,num[2]++;
if(s[i]==a3) r[3]=i,num[3]++;
}
}
int ans=1;
void dfs(char s[],char a1,char a2,char a3)
{
int now=0;
doit(s,a1,a2,a3);
if(num[1]==3) now++;
int len=0;
int slen=9;
char ss[11];
for(int i=0;i<l[1];i++){
ss[len++]=s[i];
}
for(int i=r[1]+1;i<slen;i++){
ss[len++]=s[i];
}
ss[len++]=0;
doit(ss,a1,a2,a3);
slen=len;
len=0;
for(int i=0;i<l[2];i++){
ss[len++]=ss[i];
}
for(int i=r[2]+1;i<slen;i++){
ss[len++]=ss[i];
}
ss[len++]=0;
if(num[2]==3) now++;
doit(ss,a1,a2,a3);
if(num[3]==3) now++;
ans=max(ans,now);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
char s[11];
ans=1;
scanf("%s",s);
dfs(s,'g','o','a');
dfs(s,'g','a','o');
dfs(s,'a','g','o');
dfs(s,'a','o','g');
dfs(s,'o','a','g');
dfs(s,'o','g','a');
printf("%d\n",ans);
}
return 0;
}
Time Limit: 1 Second Memory Limit: 65536 KB
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
4000
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 (about50), 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 superskill 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.
题意:
类似消消乐的游戏,问你最多能连续消除3个的操作能有几个。
POINT:
反正就3个字母,遍历这3个字母的消除顺序。
记录每个字母的最左和最右。
消除有3个就ans++。每次消除把最左到最右的字符串全部消除(因为要让他们连续)
重复操作。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#
using namespace std;
const int maxn = 1e2+10;
int l[4],r[4];
int num[4];
void doit(char s[],char a1,char a2,char a3)
{
memset(num,0,sizeof num);
memset(l,-1,sizeof l);
memset(r,-1,sizeof r);
int ll=strlen(s);
for(int i=0;i<ll;i++){
if(s[i]==a1&&l[1]==-1) l[1]=i;
if(s[i]==a2&&l[2]==-1) l[2]=i;
if(s[i]==a3&&l[3]==-1) l[3]=i;
if(s[i]==a1) r[1]=i,num[1]++;
if(s[i]==a2) r[2]=i,num[2]++;
if(s[i]==a3) r[3]=i,num[3]++;
}
}
int ans=1;
void dfs(char s[],char a1,char a2,char a3)
{
int now=0;
doit(s,a1,a2,a3);
if(num[1]==3) now++;
int len=0;
int slen=9;
char ss[11];
for(int i=0;i<l[1];i++){
ss[len++]=s[i];
}
for(int i=r[1]+1;i<slen;i++){
ss[len++]=s[i];
}
ss[len++]=0;
doit(ss,a1,a2,a3);
slen=len;
len=0;
for(int i=0;i<l[2];i++){
ss[len++]=ss[i];
}
for(int i=r[2]+1;i<slen;i++){
ss[len++]=ss[i];
}
ss[len++]=0;
if(num[2]==3) now++;
doit(ss,a1,a2,a3);
if(num[3]==3) now++;
ans=max(ans,now);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
char s[11];
ans=1;
scanf("%s",s);
dfs(s,'g','o','a');
dfs(s,'g','a','o');
dfs(s,'a','g','o');
dfs(s,'a','o','g');
dfs(s,'o','a','g');
dfs(s,'o','g','a');
printf("%d\n",ans);
}
return 0;
}
相关文章推荐
- 2017 CCPC 秦皇岛 & ZOJ 3981 - Balloon Robot 规律
- 2017 CCPC 秦皇岛 & ZOJ 3985 - String of CCPC (子串)
- 2017 CCPC 秦皇岛 & ZOJ 3987 - Numbers (贪心+大数)
- ZOJ 3983 && 2017CCPC秦皇岛 C:Crusaders Quest
- 2017 CCPC 秦皇岛 & ZOJ 3993 - Safest Buildings (概率+规律)
- ZOJ 3985 && 2017CCPC秦皇岛 E:String of CCPC
- ZOJ 3985 String of CCPC 2017秦皇岛CCPC(子串个数)
- zoj&CCPC秦皇岛站E-思维-String of CCPC
- 2017 CCPC 秦皇岛 C - Crusaders Quest 【暴力||分类】
- zoj--3983(CCPC秦皇岛)
- 2017 CCPC 秦皇岛 M - Safest Buildings 【几何&概率】
- zoj&2017CCPC秦皇岛站C-蛮力&erase细节&STL-Crusaders Quest
- 2017 CCPC 秦皇岛站 M题题解 ZOJ 3993 Safest Buildings
- 2017 秦皇岛CCPC M题 Safest Buildings(概率+思维+计算几何)
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot
- 2017 CCPC秦皇岛 B
- 2017 CCPC 秦皇岛 A:Balloon Robot
- ZOJ 3992 && 2017CCPC秦皇岛 L:One-Dimensional Maze
- 2017 CCPC秦皇岛 D
- ZOJ 3983 Crusaders Quest