链接:

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的更多相关文章

  1. 【cf比赛记录】Codeforces Round #605 (Div. 3)

    比赛传送门 Div3真的是暴力杯,比div2还暴力吧(这不是明摆的嘛),所以对我这种一根筋的挺麻烦的,比如A题就自己没转过头来浪费了很久,后来才醒悟过来了.然后这次竟然还上分了...... A题:爆搜 ...

  2. Codeforces Round #605 (Div. 3)

    地址:http://codeforces.com/contest/1272 A. Three Friends 仔细读题能够发现|a-b| + |a-c| + |b-c| = |R-L|*2 (其中L ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #605 (Div. 3) B. Snow Walking Robot(构造)

    链接: https://codeforces.com/contest/1272/problem/B 题意: Recently you have bought a snow walking robot ...

  7. Codeforces Round #605 (Div. 3) A. Three Friends(贪心)

    链接: https://codeforces.com/contest/1272/problem/A 题意: outputstandard output Three friends are going ...

  8. Codeforces Round #605 (Div. 3) 题解

    Three Friends Snow Walking Robot Yet Another Broken Keyboard Remove One Element Nearest Opposite Par ...

  9. Codeforces Round #605 (Div. 3) E - Nearest Opposite Parity (超级源点)

随机推荐

  1. 向DataGrid数据表格增加查询搜索框

    向DataGrid数据表格增加查询搜索框 效果如下: js代码: $(function(){ var dg = $('#dg').datagrid({ url:"${pageContext. ...

  2. springboot异步线程

    前言 最近项目中出现了一个问题,发现自己的定时器任务在线上没有执行,但是在线下测试时却能执行,最后谷歌到了这篇文章SpringBoot踩坑日记-定时任务不定时了?; 本篇文章主要以自己在项目中遇到的问 ...

  3. Django框架之第三篇(路由层)--有名/无名分组、反向解析、路由分发、名称空间、伪静态

    一.Django请求生命周期 二.路由层  urls.py url()方法 第一个参数其实就是一个正则表达式,一旦前面的正则匹配到了内容,就不会再往下继续匹配,而是直接执行对应的视图函数. djang ...

  4. qt5信息提示框QMessageBox用法(很全)

    information QMessageBox::information(NULL, "Title", "Content", QMessageBox::Yes ...

  5. swift版 二分查找 (折半查找)

    二分查找作为一种常见的查找方法,将原本是线性时间提升到了对数时间范围之内,大大缩短了搜索时间,但它有一个前提,就是必须在有序数据中进行查找.废话少说,直接上代码,可复制粘贴直接出结果! import ...

  6. 转:Windows下交换CapsLock和左ctrl

    Windows下交换CapsLock和左ctrlHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout中添加Scanco ...

  7. 单点logi,n

    using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; u ...

  8. URL不变的情况下,最实用的vue刷新当前页面,provide / inject 组合 方式实现vue页面刷新

    原文:https://blog.csdn.net/Dream_xun/article/details/83024487 其他参考:https://blog.csdn.net/liyunkun888/a ...

  9. rabbitmq监控之消息确认ack

    rabbitmq springboot ack 监控 一.测试环境 二.启动测试 一直以来,学习rabbitmq都是跟着各种各样的教程.博客.视频和文档,撸起袖子就是干!!!最后,也成功了. 当然,成 ...

  10. SpringBoot配置中@ConfigurationProperties和@Value的区别

    基本特征 @ConfigurationProperties 与@Bean结合为属性赋值 与@PropertySource(只能用于properties文件)结合读取指定文件 与@Validation结 ...