A:http://codeforces.com/problemset/problem/519/A

水题没什么好说的。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#define inf 0x3f3f3f3f
using namespace std;
char ma[][];
int su,su2;
int main()
{
while(scanf("%s",ma[])!=EOF)
{
su=;
su2=;
for(int i=;i<;i++)
scanf("%s",ma[i]);
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(ma[i][j]=='Q')
{
su+=;
}
else if(ma[i][j]=='q')
{
su2+=;
}
else if(ma[i][j]=='R')
{
su+=;
}
else if(ma[i][j]=='r')
{
su2+=;
}
else if(ma[i][j]=='B')
{
su+=;
}
else if(ma[i][j]=='b')
{
su2+=;
}
else if(ma[i][j]=='N')
{
su+=;
}
else if(ma[i][j]=='n')
{
su2+=;
}
else if(ma[i][j]=='P')
{
su+=;
}
else if(ma[i][j]=='p')
{
su2+=;
}
else if(ma[i][j]=='K')
{
su+=;
}
else if(ma[i][j]=='k')
{
su2+=;
}
}
}
if(su>su2)
printf("White\n");
else if(su==su2)
{
printf("Draw\n");
}
else printf("Black\n");
}
return ;
}

B:http://codeforces.com/problemset/problem/519/B

水题,简单排序即可。

#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#include <stdio.h>
#include <string.h>
typedef __int64 ll;
#define mod 10000007
using namespace std;
int n,a[],b[],c[],k;
ll sum;
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<n-;i++)
{
scanf("%d",&b[i]);
}
b[n-]=-;
for(int i=;i<n-;i++)
{
scanf("%d",&c[i]);
}
c[n-]=-;
c[n-]=-;
sort(a,a+n);
sort(b,b+n-);
sort(c,c+n-);
for(int i=;i<n;i++)
{
if(b[i]!=a[i])
{
printf("%d\n",a[i]);
break;
}
}
for(int i=;i<n-;i++)
{
if(c[i]!=b[i])
{
printf("%d\n",b[i]);
break;
}
}
}
return ;
}

C:http://codeforces.com/problemset/problem/519/C

给你n个老手,m的新手,有两种组队方式,一种是1个老手带两个新手,另外一种是2个老手带一个新手,求最多的组队对数。

我是暴力求的,记得还有一种方法,不会算了。

#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#include <stdio.h>
#include <string.h>
typedef __int64 ll;
#define mod 10000007
using namespace std;
int n,m;
ll sum;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
sum=;
while(n>&&m>)
{
if(n>=m&&n>=)
{
sum++;
n-=;
m-=;
}
else if(m>=)
{
sum++;
n-=;
m-=;
}
else break;
}
printf("%I64d\n",sum);
}
return ;
}

D. A and B and Interesting Substrings

题意:在给的一个串,每个字母有固定的权值求满足如下条件的子串的数目

1 该子串的首字母和尾字母相同

2 该串除了首尾字母外,其他字母的权值和为0

思路:维护一个前缀和,用了26个hash分别记录了26种字母每个的前缀和,如果遇到了一个'a',就检查之前有几个和他的前缀和一样的'a',在和上加上去,并维护前缀和。

map真的是好牛逼,可惜比赛的时候没想到,希望以后会用吧!

#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#include <stdio.h>
#include <string.h>
typedef __int64 ll;
#define mod 10000007
using namespace std;
int h[];
char s[];
ll sum,cnt;
int main()
{
while(scanf("%d",&h[])!=EOF)
{
cnt=;
sum=;
for(int i=;i<;i++)
{
scanf("%d",&h[i]);
}
scanf("%s",s);
int l=strlen(s);
map<ll,ll>q[]; //map<ll,int>q[30];
for(int i=;i<l;i++)
{
cnt+=q[s[i]-'a'][sum];
sum+=h[s[i]-'a'];
q[s[i]-'a'][sum]++;
}
printf("%I64d\n",cnt);
}
return ;
}

CF519 ABCD D. A and B and Interesting Substrings(map,好题)的更多相关文章

  1. [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】

    题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...

  2. Codeforces Round #294 (Div. 2)D - A and B and Interesting Substrings 字符串

    D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megaby ...

  3. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

    传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...

  4. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings

    题意: 对于26个字母 每个字母分别有一个权值 给出一个字符串,找出有多少个满足条件的子串, 条件:1.第一个字母和最后一个相同,2.除了第一个和最后一个字母外,其他的权和为0 思路: 预处理出sum ...

  5. cf519D . A and B and Interesting Substrings 数据结构map

    题意: 已知26个小写字母有各自的权值(正,负,或0) 现在给出一个字符串,长度<=1e5 问这个字符串有多少个子串满足: 开头的字母和结尾的字母一样 字符串除了开头和结尾的字母外,其余的字母的 ...

  6. Codeforces 519D A and B and Interesting Substrings(二维map+前缀和)

    题目链接:http://codeforces.com/problemset/problem/519/D 题目大意:给你一串字符串s仅由小写字母组成,并且对于'a'~'z'都给了一个值.求子串t满足t的 ...

  7. cf519D. A and B and Interesting Substrings(前缀和)

    题意 给出$26$个字母对应的权值和一个字符串 问满足以下条件的子串有多少 首尾字母相同 中间字母权值相加为0 Sol 我们要找到区间满足$sum[i] - sum[j] = 0$ $sum[i] = ...

  8. CodeForces 519D A and B and Interesting Substrings ——(奥义字符串)

    题意:给出26个字母每个字母的价值,问字符串中有多少个满足以下条件的子串: 1.子串的第一个和最后一个相同 2.子串除了头和尾的其他字符的价值加起来和尾0 这题普通方法应该是O(n^2),但是在1e5 ...

  9. Spring IoC介绍与Bean的使用

    1. 介绍 IoC   IoC-Inversion of Control,即"控制反转",它不是什么技术,而是一种设计思想.在 Java 开发中, IoC意味着将设计好的对象交给容 ...

随机推荐

  1. 【BZOJ】1042: [HAOI2008]硬币购物(dp+容斥原理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1042 一开始写了个O(nv)的背包,果断tle... 看了题解,,好神..用了组合数学中的多重集合方 ...

  2. PyQt的Layout的比例化分块。

    一. QGridLayout: // 列比 第0列与第1列之比为 1:2 layout2p1 -> setColumnStretch(0, 1); layout2p1 -> setColu ...

  3. Python零碎(一)

    Python中的__name__和__main__含义详解 在写Python代码和看Python代码时,我们常常可以看到这样的代码: def main(): ...... if __name == & ...

  4. Angular2 Observable 可观察对象

    可观察对象支持在应用中的发布者和订阅者之间传递消息.在需要进行事件处理,异步编程和处理多值的时候,可观察对象相对其他技术有显著的优点. 可观察对象是声明式的 —— 也就是说,虽然你定义了一个用于发布值 ...

  5. 【ArcGIS for Android】经纬度坐标、地图投影坐标、屏幕坐标互相转换

    SpatialReference mSR4326 = SpatialReference.create(4326); SpatialReference mSR3857 = SpatialReferenc ...

  6. 使用 composer 下载更新卸载类库

    前言:要下载什么包,可以去 https://packagist.org/ 找一下包名及其版本信息 1)配置composer.json文件,并使用composer install 命令下载类包,下面以下 ...

  7. JZOJ.5327【NOIP2017模拟8.21】四驱兄弟

    Description

  8. 【BZOJ3585/3339】mex 莫队算法+分块

    [BZOJ3585]mex Description 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. Input 第一行n,m. 第二行为n个数. ...

  9. oracle如何给指定用户修改密码?

    1.用system用户登录, 2.执行如下sql: alter user 用户名 identified by 新密码; 比如alter user scott identified by 123456; ...

  10. Block Formatting Contexts (块级格式化上下文) 使用参考

    转自:http://kayosite.com/block-formatting-contexts-in-detail.html 在上文<详说清除浮动>中,Kayo 较为详细地介绍了 BFC ...