CodeForces 519D A and B and Interesting Substrings 前缀和
来源:互联网 发布:淘宝店铺被关闭 编辑:程序博客网 时间:2024/05/29 19:37
题意:给出26个小写字母的权值,给出一个字符串s,要求找出所有这样的子串,他们的首尾字符相同,并且除了首尾外其余字母首尾之和为0的子串。将数目输出出来。
思路:找前缀和相同,并且字符相同的数目。
简直是黑科技
#include<cstdio>#include<queue>#include<iostream>#include<vector>#include<map>#include<cstring>#include<string>#include<set>#include<stack>#include<algorithm>#define cle(a) memset(a,0,sizeof(a))#define inf(a) memset(a,ox3f,sizeof(a))#define ll long long#define Rep(i,a,n) for(int i=a;i<=n;i++)using namespace std;const int INF = ( 2e9 ) + 2;const int maxn = 28;const int maxm = 1e5+10;map<ll,ll> mp[26];// 找前缀和相同的两个字符 int a[maxn];char s[maxm];int main(){//freopen("in.txt","r",stdin);for(int i=0;i<26;i++)scanf("%d",&a[i]);scanf("%s",s+1);int len=strlen(s+1);ll ans=0,pre=0;for(int i=1;i<=len;i++){int m=s[i]-'a';ans+=mp[m][pre];pre+=a[m];mp[m][pre]++;}printf("%I64d\n",ans);}
阅读全文
0 0
- Codeforces 519D A and B and Interesting Substrings (前缀和)
- CodeForces - 519D A and B and Interesting Substrings (前缀和)
- CodeForces 519D A and B and Interesting Substrings 前缀和
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings(前缀和+map)
- CodeForces 19D A and B and Interesting Substrings 【前缀和】
- Codeforces 519D - A and B and Interesting Substrings (思维)
- Codeforces 519D A and B and Interesting Substrings
- A and B and Interesting Substrings - CodeForces 519 D dp
- CodeForces 519D A and B and Interesting Substrings
- 前缀和STL CF D A and B and Interesting Substrings
- codeforces A and B and Interesting Substrings
- codeforces 519D D. A and B and Interesting Substrings(hash+dp)
- Codefources 519D. A and B and Interesting Substrings
- coderforce 519D A and B and Interesting Substrings
- Codeforces 519D A and B and Interesting Substrings (简单hash)
- Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings
- hash(Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings)
- Codeforces Round #294 (Div. 2) -- D. A and B and Interesting Substrings
- Material Design控件使用(二)
- 设计模式第七种原则
- 毛驴和萝卜问题
- AI“末世论” To Be or Not to Be?
- 当UILabel 中的内容太长情况下的设置
- CodeForces 519D A and B and Interesting Substrings 前缀和
- bzoj 2510 弱题 矩阵乘
- Matlab中mesh函数的用法
- Struts2的文件上传和下载
- HDU 6038 Function (2017多校1 -- 找循环节计数)
- 1-2:div、span、css
- 动态设置TextView的对齐方式以及getLineCount的使用
- You Only Look Once: Unified, Real-Time Object Detection
- Material Design控件使用(三)