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. HeadFirst jsp 08 无脚本JSP

    web页面设计人员真的必须懂 java ? web页面人员可以很快学习 EL 语言. 目前不知道 EL 应用前景如何, 但是我们香港系统没有使用 EL. include 指令 include指令告诉容 ...

  2. [android] AndroidManifest.xml【 manifest -> uses-permission】

    在  API Level 1 时被引入 简介: 在某些情况下,你为app设置的权限将会影响到google应用商店会用何种规则来过滤你的APP. 如果你需要一个硬件相关的权限——CAMERA,googl ...

  3. Think Python: How to Think Like a Computer Scientist

    Think Python: How to Think Like a Computer Scientist:http://greenteapress.com/thinkpython/html/index ...

  4. ACM计算几何模板——圆和球

    #include <iostream> #include <cmath> using namespace std; #define eps 1e-10 /********** ...

  5. Java 执行linux scp 远程获取文件和上传

      需要的jar包:ganymed-ssh2-build210.jar import java.io.ByteArrayOutputStream;import java.io.File;import ...

  6. flex布局,input点击软键盘激活,底部按钮上移

    安卓手机的问题,原本表单没有超出一屏的时候,上移的现象也是存才的,只是需要滑动body才能看得到,现在,超出一屏了,现象就很明显了 body明显上移: 点击input修改价格: 软键盘出现: 先尝试了 ...

  7. 一 Android Studio 打包Egret App

    测试环境: Android Studio 2.3.2 Egret Engine 5.0.14 Egret Support5.0.12 官网教程:http://developer.egret.com/c ...

  8. LeetCode 笔记系列12 Trapping Rain Water [复杂的代码是错误的代码]

    题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, com ...

  9. centos7 安装kafka Manager

    1.安装sbt编译环境 curl https://bintray.com/sbt/rpm/rpm |tee /etc/yum.repos.d/bintray-sbt-rpm.repo yum inst ...

  10. jenkins multijob 插件使用

    如果你想要停止对下游/上游工作链定义的混乱 当您想要添加具有层次结构的任务时,按顺序执行或并行执行 安装multijob插件可以让jenkins任务按照分组.顺序执行 jenkins版本:2.80 1 ...