Codeforces Round #605 (Div. 3) C. Yet Another Broken Keyboard
链接:
https://codeforces.com/contest/1272/problem/C
题意:
Recently, Norge found a string s=s1s2…sn consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all n(n+1)2 of them!
A substring of s is a non-empty string x=s[a…b]=sasa+1…sb (1≤a≤b≤n). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c1,c2,…,ck out of 26.
After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.
思路:
遍历一边计数,一个长为n的串的所有子串是1+2++n。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5;
char s[MAXN];
int main()
{
int n, k;
cin >> n >> k;
cin >> s;
map<char, bool> Mp;
char c;
for (int i = 1;i <= k;i++)
{
cin >> c;
Mp[c] = true;
}
int len = strlen(s);
LL ans = 0, tmp = 0;
for (int i = 0;i < len;i++)
{
if (!Mp[s[i]])
{
ans += (1+tmp)*tmp/2;
tmp = 0;
continue;
}
tmp++;
}
if (tmp > 0)
ans += (1+tmp)*tmp/2;
cout << ans << endl;
return 0;
}
Codeforces Round #605 (Div. 3) C. Yet Another Broken Keyboard的更多相关文章
- 【cf比赛记录】Codeforces Round #605 (Div. 3)
比赛传送门 Div3真的是暴力杯,比div2还暴力吧(这不是明摆的嘛),所以对我这种一根筋的挺麻烦的,比如A题就自己没转过头来浪费了很久,后来才醒悟过来了.然后这次竟然还上分了...... A题:爆搜 ...
- Codeforces Round #605 (Div. 3)
地址:http://codeforces.com/contest/1272 A. Three Friends 仔细读题能够发现|a-b| + |a-c| + |b-c| = |R-L|*2 (其中L ...
- Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity
题目链接:http://codeforces.com/contest/1272/problem/E 题意:给定n,给定n个数a[i],对每个数输出d[i]. 对于每个i,可以移动到i+a[i]和i-a ...
- Codeforces Round #605 (Div. 3) E. Nearest Opposite Parity(最短路)
链接: https://codeforces.com/contest/1272/problem/E 题意: You are given an array a consisting of n integ ...
- Codeforces Round #605 (Div. 3) D. Remove One Element(DP)
链接: https://codeforces.com/contest/1272/problem/D 题意: You are given an array a consisting of n integ ...
- Codeforces Round #605 (Div. 3) B. Snow Walking Robot(构造)
链接: https://codeforces.com/contest/1272/problem/B 题意: Recently you have bought a snow walking robot ...
- Codeforces Round #605 (Div. 3) A. Three Friends(贪心)
链接: https://codeforces.com/contest/1272/problem/A 题意: outputstandard output Three friends are going ...
- Codeforces Round #605 (Div. 3) 题解
Three Friends Snow Walking Robot Yet Another Broken Keyboard Remove One Element Nearest Opposite Par ...
- Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity (超级源点)
随机推荐
- SQL Server 中关于系统库Tempdb总结
Tempdb系统数据库是一个全局资源,可供连接到SQL Server实例的所有用户使用. 存储的内容项: 1.用户对象 用户对象由用户显示创建.这些对象可以位于用户会话的作用域中,也可以位于创建对象所 ...
- IDEA中MavenWeb项目没有新建servlet文件
解决方案: https://blog.csdn.net/Delicious_Life/article/details/89515363
- C++ 每日一题 参数分析 (vector)
首先给出原题地址: https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677?tpId 以下是代码解析: #include& ...
- STM32学习笔记 —— 1.1 什么是寄存器(概念分析)
问题引入: 用一句话回答以下问题: 什么是寄存器? 什么是寄存器映射? 什么是存储器映射? (本章重点在 1.1.3 和 1.1.4) 1.1 STM32芯片实物图 (图) 学会看丝印图 芯片型号.内 ...
- 【Go】开发中遇到的坑——持续更新
关于CGo多语言编译 问题出现在将openCV封装到go语言的时候.在编译时需要设置 CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o xxx mai ...
- NFS实现多服务器文件共享
服务器 1.安装所需的软件包 yum install -y rpc-bind nfs-utils 2.设为开机自启动 systemctl enable nfs systemctl enable rpc ...
- nacos初探--作为配置中心
什么是nacos Nacos 支持基于 DNS 和基于 RPC 的服务发现(可以作为springcloud的注册中心).动态配置服务(可以做配置中心).动态 DNS 服务. 官方介绍是这样的: Nac ...
- Mysql批量更新的三种方式
前言 批量插入由于mysql的VALUES原生支持,使用较为便利. 批量更新的写法一般有三种,在更新数量较少的情况下,前两种性能不相上下.但是在更新字段增加,更新条数较多(500以上)建议使用第三种写 ...
- 通过分析 WPF 的渲染脏区优化渲染性能
原文:通过分析 WPF 的渲染脏区优化渲染性能 本文介绍通过发现渲染脏区来提高渲染性能. 本文内容 脏区 Dirty Region WPF 性能套件 脏区监视 优化脏区重绘 脏区 Dirty Regi ...
- Django使用 django-allauth实现第三方登陆
Django使用 django-allauth实现第三方登陆 这里我们使用 django-allauth 模块来实现第三方账号验证登录,官方文档如下:https://django-allauth.re ...