H

Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday.

It is known that Mrs. Panda does not like a song if and only if its lyrics contain Xvowels in a row, or Y consonants in a row (Otherwise, Mrs. Panda likes the song). The letters 'a', 'e', 'i', 'o', 'u' are vowels, and all others are consonants.

Though Mr. Panda is a gifted singer, he is bad at composing lyrics. Mr. Panda wants the song to be special. Thus, he searched Google for a template for lyrics of the song.

The template consists of lowercase English letters and possibly question marks. For example, "happybirthday" (without quotes, the same below), "????ybirthday" are valid templates but neither "happy birthday" nor "HappyBirthday" is. Mr. Panda needs to substitute all the question marks with lowercase English letters so that it becomes actual lyrics of the song.

Mr. Panda wants to give a surprise to Mrs. Panda. So, Mr. Panda hopes to compose not only a song from the template that Mrs. Panda likes but also a song from the same template that Mrs. Panda dislikes.

Because Mr. Panda is really bad at composing lyrics, even with a template, the task has confused him for days. Luckily, Mr. Panda knows you are in the contest and wants to ask you for help.

For a given template, output either "DISLIKE" (without quotes, the same below) if Mrs. Panda dislikes all the songs that are generated from the template (that means you cannot substitute letters for question marks so that Mrs. Panda likes the song), "LIKE" if Mrs. Panda likes all the songs that are generated from the template, or "SURPRISE" if Mr. Panda can compose a song Mrs. Panda likes and another song Mrs. Panda dislikes.

Input

The first line of the input gives the number of test cases, an integer TT test cases follow.

Each test case consists of a line containing a string S, the template that Mr. Panda gets, an integer X, the minimum number of continuous vowels that Mrs. Panda dislikes, and an integer Y, the minimum number of continuous consonants that Mrs. Panda dislikes. In the template S, each character can be either one of lowercase English letters ('a’ to 'z’) or question mark ('?’).

  • 1 ≤ T ≤ 300.
  • 2 ≤ |S| ≤ 106.
  • 1 ≤ X ≤ |S|.
  • 1 ≤ Y ≤ |S|.
  • Sum of |S| over all test cases  ≤ 5 × 107.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y can be either "LIKE", "DISLIKE" or "SURPRISE" as mentioned in the problem description.

Example

Input
5
happybirthda? 3 4
happybirth?ay 3 5
happybirthd?y 3 5
hellow?rld 3 5
helllllowooorld 3 5
Output
Case #1: DISLIKE
Case #2: LIKE
Case #3: SURPRISE
Case #4: SURPRISE
Case #5: DISLIKE

精选博客题解:https://blog.csdn.net/Link_Ray/article/details/89740922

题意
连续出现元音长度 >= x || 连续出现辅音长度 >= y ,输出DISLIKE。
连续出现元音长度 < x && 连续出现辅音长度 <y,输出LIKE。
即满足1又满足2,输出SURPRISE。
题解
对于1,直接贪心求最大的连续元音/辅音次数,即遇到?时,元/辅音都+1。

对于2,采用dp。
0: 元音,1:辅音
设dp[i][0/1] dp[i][0/1]dp[i][0/1]:到第i位时连续的元/辅音最小长度。
状态转移:

ch == 元音
dp[i][0]=dp[i−1][0]+1,dp[i][1]=0 dp[i][0] = dp[i-1][0]+1,dp[i][1] = 0
dp[i][0]=dp[i−1][0]+1,dp[i][1]=0
ch == 辅音
dp[i][1]=dp[i−1][1]+1,dp[i][0]=0 dp[i][1] = dp[i-1][1]+1,dp[i][0] = 0
dp[i][1]=dp[i−1][1]+1,dp[i][0]=0
ch == ?

如果dp[i-1][0]+1 < x,那么便可以把?变成元音

如果dp[i-1][1]+1 < y,那么便可以把?变成辅音

则:

如果当前位既可填元音又可填辅音:dp[i][0] = dp[i][1] = 0.

如果当前位只可填元音:dp[i][0] = dp[i-1][0] + 1, dp[i][1] = 0;

如果当前为只可填辅音:dp[i][1] = dp[i-1][1] + 1, dp[i][0] = 0;

如果都不可以填,则必然不能出现like的情况,break.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=2147493647;
const int maxn = 1000010;
char s[maxn];
int dp[maxn][2],x,y;
int ok(char c)
{
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')return 1;
  return 0;
}
int main()
{
  ios::sync_with_stdio(0);
  int T,k = 1;
  cin >> T;
  while(T--){
    cin >> (s+1);
    cin >> x >> y;
    int n = strlen(s+1);
    int dislike=0,like=1;
    memset(dp,0,sizeof(dp));
    for(int i = 1;i <= n;i++){//贪心求出是否有dislike的情况,这时dp[i][0/1]代表到目前为止元(辅)音的最大长度
      if(s[i] == '?'){
        dp[i][0] = dp[i-1][0]+1;
        dp[i][1] = dp[i-1][1]+1;
      }
      else if(ok(s[i])){
        dp[i][0] = dp[i-1][0]+1;
      }
      else{
        dp[i][1] = dp[i-1][1]+1;
      }
      if(dp[i][0] >= x || dp[i][1] >= y){
        dislike = 1;
        break;
      }
    }
    memset(dp,0,sizeof(dp));
    for(int i = 1;i <= n;i++){//dp求出是否可以满足like,这时dp[i][0/1]代表到目前为止填元(辅)音的最小长度
      if(s[i] == '?'){
        if(dp[i-1][0] + 1 < x && dp[i-1][1] + 1 < y){//元音辅音都可以填
          dp[i][0] = dp[i][1] = 0;
        }
        else if(dp[i-1][0] + 1 < x){//只可填元音
          dp[i][0] = dp[i-1][0] + 1;
          dp[i][1] = 0;
        }
        else if(dp[i-1][1] + 1 < y){//只可填辅音
          dp[i][1] = dp[i-1][1] + 1;
          dp[i][0] = 0;
        }
        else{//都不能填,跳出循环
          like = 0;
          break;
        }
      }
      else if(ok(s[i])){//元音
        dp[i][0] = dp[i-1][0] + 1;
      }
      else{//辅音
        dp[i][1] = dp[i-1][1] + 1;
      }
      if(dp[i][0] >= x || dp[i][1] >= y){//判断到目前为止,是否有不满足条件的
        like = 0;
        break;
      }
    }
    cout << "Case #"<<k++<<": ";
    if(dislike && like)cout << "SURPRISE" << endl;
    else if(dislike)cout << "DISLIKE" << endl;
    else cout << "LIKE" << endl;
  }
  return 0;
}
原文地址:https://www.cnblogs.com/cherish-lin/p/11766223.html