zoukankan      html  css  js  c++  java
  • 2018 CCPC秦皇岛 C题 Crusader Quest

    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.

    <h4< dd="">Output

    For each test case, output an integer denoting the maximum number of times DreamGrid can trigger the super skill.

    <h4< dd="">Sample Input

    7
    gggaaaooo
    aaoogggoa
    googgaaao
    agogaooag
    goooggaaa
    gogogoaaa
    gaogaogao

    <h4< dd="">Sample Output

    3
    3
    2
    1
    3
    2
    1

    <h4< dd="">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.

    题解:暴力即可;

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 int cnt[26];
     5 int l[26], r[26];
     6 char s[15];
     7 char id[6][3] = {{'a','o','g'},
     8                  {'a','g','o'},
     9                  {'o','a','g'},
    10                  {'o','g','a'},
    11                  {'g','a','o'},
    12                  {'g','o','a'} };
    13 
    14 int check(char m[3])
    15 {
    16     int num = 0;
    17     cnt['a'-'a'] = cnt['o' - 'a'] = cnt['g' - 'a'] = 3;
    18     for(int i = 0; i < 3; i++)
    19     {
    20         if(cnt[m[i] - 'a'] == 3)
    21         {
    22             num++;
    23             for(int j = l[m[i] - 'a']; j <= r[m[i] - 'a']; j++)
    24             {
    25                 cnt[s[j] - 'a']--;
    26             }
    27         }
    28     }
    29     return num;
    30 }
    31 
    32 
    33 int main()
    34 {
    35     int n;
    36     scanf("%d", &n);
    37     while(n--)
    38     {
    39         scanf("%s", s);
    40         l['a'-'a'] = l['o' - 'a'] = l['g' - 'a'] = 100;
    41         r['a'-'a'] = r['o' - 'a'] = r['g' - 'a'] = -1;
    42         for(int i = 0; i < 9; i++)
    43         {
    44             l[s[i] - 'a'] = min(l[s[i] - 'a'], i);
    45             r[s[i] - 'a'] = max(r[s[i] - 'a'], i);
    46         }
    47         int ans = 0;
    48         for(int i = 0; i < 6; i++)
    49             ans = max(ans, check(id[i]));
    50         printf("%d
    ", ans);
    51     }
    52     return 0;
    53 }
    View Code

      

  • 相关阅读:
    磁盘冗余阵列之RAID 5
    磁盘冗余阵列之RAID10
    Linux常见的命令与vi的介绍
    通过挂在系统光盘搭建本地yum
    Windows 2008 系统安装
    在windows主机中,利用XSHELL生成“密钥”进行虚拟机与物理机的传输
    在VMware下进行的使用ssh服务管理远程主机
    Linux中的快捷方式
    Linux中常用命令
    Linux中vi命令的详细总结
  • 原文地址:https://www.cnblogs.com/csushl/p/9787680.html
Copyright © 2011-2022 走看看