H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)
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 T. T 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
- 5
happybirthda? 3 4
happybirth?ay 3 5
happybirthd?y 3 5
hellow?rld 3 5
helllllowooorld 3 5
- 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=;
- const int maxn = ;
- char s[maxn];
- int dp[maxn][],x,y;
- int ok(char c)
- {
- if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')return ;
- return ;
- }
- int main()
- {
- ios::sync_with_stdio();
- int T,k = ;
- cin >> T;
- while(T--){
- cin >> (s+);
- cin >> x >> y;
- int n = strlen(s+);
- int dislike=,like=;
- memset(dp,,sizeof(dp));
- for(int i = ;i <= n;i++){//贪心求出是否有dislike的情况,这时dp[i][0/1]代表到目前为止元(辅)音的最大长度
- if(s[i] == '?'){
- dp[i][] = dp[i-][]+;
- dp[i][] = dp[i-][]+;
- }
- else if(ok(s[i])){
- dp[i][] = dp[i-][]+;
- }
- else{
- dp[i][] = dp[i-][]+;
- }
- if(dp[i][] >= x || dp[i][] >= y){
- dislike = ;
- break;
- }
- }
- memset(dp,,sizeof(dp));
- for(int i = ;i <= n;i++){//dp求出是否可以满足like,这时dp[i][0/1]代表到目前为止填元(辅)音的最小长度
- if(s[i] == '?'){
- if(dp[i-][] + < x && dp[i-][] + < y){//元音辅音都可以填
- dp[i][] = dp[i][] = ;
- }
- else if(dp[i-][] + < x){//只可填元音
- dp[i][] = dp[i-][] + ;
- dp[i][] = ;
- }
- else if(dp[i-][] + < y){//只可填辅音
- dp[i][] = dp[i-][] + ;
- dp[i][] = ;
- }
- else{//都不能填,跳出循环
- like = ;
- break;
- }
- }
- else if(ok(s[i])){//元音
- dp[i][] = dp[i-][] + ;
- }
- else{//辅音
- dp[i][] = dp[i-][] + ;
- }
- if(dp[i][] >= x || dp[i][] >= y){//判断到目前为止,是否有不满足条件的
- like = ;
- break;
- }
- }
- cout << "Case #"<<k++<<": ";
- if(dislike && like)cout << "SURPRISE" << endl;
- else if(dislike)cout << "DISLIKE" << endl;
- else cout << "LIKE" << endl;
- }
- return ;
- }
H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)的更多相关文章
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...
- hdu6007 Mr. Panda and Crystal 最短路+完全背包
/** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...
- Gym 101194C / UVALive 7899 - Mr. Panda and Strips - [set][2016 EC-Final Problem C]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- Codeforces Gym 101194C Mr. Panda and Strips(2016 EC-Final,区间DP预处理 + 枚举剪枝)
题目链接 2016 EC-Final 题意 现在要找到数列中连续两个子序列(没有公共部分).要求这两个子序列本身内部没有重复出现的数. 求这两个子序列的长度的和的最大值. 首先预处理一下.令$ ...
- Gym 101194F Mr. Panda and Fantastic Beasts
#include<bits/stdc++.h> using namespace std; #define ms(arr,a) memset(arr,a,sizeof arr) #defin ...
- Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,D题,枚举剪枝)
题目链接 ECL-Final 2017 Problem D 题意 给定$2*10^{5}$组询问,每个询问求$l$到$r$之间有多少个符合条件的数 如果一个数小于等于$10^{15}$, 并且能被 ...
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr. Panda and Fantastic Beasts
地址:http://codeforces.com/gym/101194 题目:略 思路: 这题做法挺多的,可以sam也可以后缀数组,我用sam做的. 1.我自己yy的思路(瞎bb的) 把第一个串建立s ...
- Mr. Panda and Crystal(最短路+完全背包)
http://codeforces.com/gym/101206/attachments 题意: T组输入,每组给出m,n,k,m为能量总数,n为水晶种类数,k为合成方案数.有的水晶可以用能量制造,有 ...
- (CCPC-Final 2018)K - Mr. Panda and Kakin
题意:x是\([1e5,1e9]\)的随机数,p是小于x的最大素数,q是大于等于x的最小素数,\(n=pq\),\(c=f^{2^{30}+3}\mod{n}\),给n和c求f 题解:rsa解密,首先 ...
随机推荐
- Arduino -- functions
For controlling the Arduino board and performing computations. Digital I/O digitalRead() digitalWrit ...
- java课程课后作业190606之计算最长英语单词链
一个文本文件中有N 个不同的英语单词, 我们能否写一个程序,快速找出最长的能首尾相连的英语单词链,每个单词最多只能用一次.最长的定义是:最多单词数量,和单词中字母的数量无关. 统一输入文件名称:inp ...
- 在开发过程中遇到的Oracle的坑及开发技巧
本人与2018年毕业,工作一年多,仍是菜鸟,自毕业以来一直从事java软件开发工作,工作中大部分数据库都是使用的Oracle,碰到的问题总结一下(随时更新). 1.sql中使用group by 分组时 ...
- sql 常用的语句(sql 创建表结构 修改列 清空表)
1.创建表 create Table WorkItemHyperlink ( ID bigint primary key ,--主键 WorkItemID ,) not null,--其中identi ...
- stm32cube 安装 patch
首先正常安装芯片包,然后在设置里面找到当前包存放的位置,默认是: C:\Users\Administrator\STM32Cube\Repository 然后解压 更新包,把更新包里面的文件覆盖到 C ...
- HZNU-ACM寒假集训Day6小结 线性DP
线性DP 考虑一组硬币面值 1,5,11 给定W,求凑出W的最少硬币个数 我们记凑出n需要用到的最少硬币数量为f(n) 我们注意到了一个很棒的性质 : f(n)只与f(n-1) f(n-5) f( ...
- 2.在约会网站上使用k近邻算法
在约会网站上使用k近邻算法 思路步骤: 1. 收集数据:提供文本文件.2. 准备数据:使用Python解析文本文件.3. 分析数据:使用Matplotlib画二维扩散图.4. 训练算法:此步骤不适用于 ...
- mybatis的批量update
方法有三种:1.通过java代码batch方式,xml文件只需一条update语句.java代码繁琐 2.xml使用foreach,“;”分割多条update语句,要求:jdbc的url需加上allo ...
- 程序员必备:详解XSS和CSRF
做开发的小伙伴想必都不陌生XSS 和 CSRF,但也有一些刚接触的朋友还不是很清楚,今天就给大家详解下XSS和CSRF! 一.XSS xss,即 Cross Site Script,中翻译是跨站脚本攻 ...
- 阿里云-容器服务之集群服务 k8s(Jenkins+gitlab+k8s的devops)- 04
配置jenkins和gitlab: 1.进入jenkins,新增一个项目,demo-piepeline,创建好,点击配置, 2 .设置镜像地址的命名空间: 3.设置镜像的名字 4.设置代码的分支或者t ...