您的位置:首页 > 其它

CodeForces Round #294 Div.2

2015-03-01 20:13 309 查看
这个题目感觉略简单,但是后两题还是一个没做出来╮(╯_╰)╭

A. A and B and Chess

就是比较一下棋盘上两边的权重。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100000 + 10;

int w[30];
char s[maxn];
LL sum[maxn];
map<LL, int> cnt[30];

int main()
{
//freopen("in.txt", "r", stdin);

for(int i = 0; i < 26; i++) scanf("%d", &w[i]);
scanf("%s", s + 1);
int l = strlen(s + 1);
LL ans = 0;
for(int i = 1; i <= l; i++)
{
int x = s[i] - 'a';
sum[i] = sum[i - 1] + w[x];
ans += cnt[x][sum[i-1]];
cnt[x][sum[i]]++;
}

printf("%I64d\n", ans);

return 0;
}


代码君
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: