[USACO23OPEN] Pareidolia S
[USACO23OPEN] Pareidolia S
USACO23OPEN] Pareidolia S - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目背景
Note: The time limit for this problem is 4s, 2x the default.
Pareidolia is the phenomenon where your eyes tend to see familiar patterns in
images where none really exist -- for example seeing a face in a cloud. As you
might imagine, with Farmer John's constant proximity to cows, he often sees
cow-related patterns in everyday objects. For example, if he looks at the
string "bqessiyexbesszieb", Farmer John's eyes ignore some of the letters and
all he sees is "bessiebessie".
题面翻译
Farmer John有的时候看东西会忽略一些字母,如把 bqessiyexbesszieb
看成 bessiebessie
。定义 bessie
相连的形式 (bessiebessiebessieb...
),返回 bessie
的最大数量。如
题目描述
Given a string
of "bessie" one can form by deleting zero or more of the characters from
In the example above,
Computing
solving a challenge that is even more interesting: Given a string
at most
输入格式
The input consists of a nonempty string of length at most
characters are all lowercase English letters.
输出格式
Output a single number, the total number of bessies that can be made across all
substrings of the input string.
样例 #1
样例输入 #1
bessiebessie
样例输出 #1
14
样例 #2
样例输入 #2
abcdefghssijebessie
样例输出 #2
28
提示
For the first sample, twelve substrings contain exactly
- Inputs 3-5: The string has length at most
. - Inputs 6-12: No additional constraints.
分析
考试时想到了假的
设
设最后一个字符串的开头位于
则
答案为
再维护一下开头的位置就好了,不会的可以看一下代码
code
#include <bits/stdc++.h>
#define fu(x , y , z) for(int x = y ; x <= z ; x ++)
using namespace std;
const int N = 3e5 + 5;
int len , a[N];
long long f[10] , ans , dp[N];
char s[N];
int main () {
scanf ("%s" , s + 1);
len = strlen (s + 1);
// bessie
// 123342
// 123645
fu (i , 1 , len) {
if (s[i] == 'b') f[1] = i;
if (s[i] == 'e') f[6] = f[5] , f[2] = f[1];
if (s[i] == 's') f[4] = f[3] , f[3] = f[2];
if (s[i] == 'i') f[5] = f[4];
dp[i] = dp[f[6] - 1] + f[6];
}
fu (i , 1 , len)
ans += dp[i];
printf ("%lld" , ans);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端