链接:

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. 【转帖】极简Docker和Kubernetes发展史

    极简Docker和Kubernetes发展史 https://www.cnblogs.com/chenqionghe/p/11454248.html 2013年 Docker项目开源 2013年,以A ...

  2. Linux Docker Introduction

    Setup on Ubuntu. 前提条件: Docker需要两个重要的安装要求: 它仅适用于64位Linux安装,注意:是64位的Linux系统. 它需要Linux内核版本3.10或更高版本. 要查 ...

  3. day55——django引入、小型django(socket包装的服务器)

    day55 吴超老师Django总网页:https://www.cnblogs.com/clschao/articles/10526431.html 请求(网址访问,提交数据等等) request 响 ...

  4. C# 历遍对象属性

    今天有个网友问如何历遍对象的所有公共属性,并且生成XML.采用序列化方式的话比较简单,我写个手工解析的例子,这样能让初学者更加理解也比较灵活,记录一下吧或许会有人用到. 对象模型: public cl ...

  5. 记一次redis主从同步失败

    zabbix告警突然从某个时间点开始提示CPU使用高,网卡流量也一直居高不下. 首先查看redis日志,发现告警时间点redis主节点被重启了,发生了主备切换,并且在日志中发现这么一段 [3081] ...

  6. volatile 作用

    volatile使用场景:线程间共享变量需要使用 volatile 关键字标记,确保线程能够读取到更新后的最新变量值. volatile关键字的目的是告诉虚拟机: 1.每次访问变量时,总是获取主内存的 ...

  7. c#利用定时器自动备份数据库(mysql)

    1:引用dll MySql.Data.dll,   MySqlbackup.dll 2:建一个数据连接静态类 public static class mysql{public static strin ...

  8. 数组中[::-1]或[::-n]的区别,如三维数组[:,::-1,:]

    import numpy as npa=np.array([[11,12,13,14,15,16,17,18],[21,22,23,24,25,26,27,28],[31,32,33,34,35,36 ...

  9. 【开发笔记】- Velocity中特殊符号展示乱码的问题

    问题 需求是需要在后台将收货国家对应的币种.币种符号返回给前台并展示,在返回给前端后出现了页面币种符号展示乱码的问题. 解决方式 在获取货币符号时添加以下代码,防止velocity对特殊符号进行转义处 ...

  10. Javascript处理数组的方法

    一 迭代方法 ES5为数组定义了5个迭代方法,这些方法大大方便了处理数组的任务,支持这些方法的浏览器有 IE9+,Firefox2+,Safari3+,Opera9.5+和Chrome. 1 ever ...