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. pycharm Tab键设置成4个空格

    file--->setting,选择Editor--->python,如下图所示:

  2. malloc 返回值的类型是 void *

    malloc 返回值的类型是 void *,所以在调用 malloc 时要显式地进行类型转换,将 void * 转换成所需要的指针类型. #include <iostream> using ...

  3. php -- 魔术方法 之 自动加载:__autoload()

    自动加载类 背景: 很多开发者写面向对象的应用程序时对每个类的定义建立一个 PHP 源文件.一个很大的烦恼是不得不在每个脚本开头写一个长长的包含文件列表(每个类一个文件). 在 PHP 5 中,不再需 ...

  4. 【BZOJ】1096: [ZJOI2007]仓库建设(dp+斜率优化)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1096 首先得到dp方程(我竟然自己都每推出了QAQ)$$d[i]=min\{d[j]+cost(j+ ...

  5. Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication 解决办法

    相信很多人都遇到过这个问题,用Android Studio正在运行程序的时候,突然不知道什么原因,报一个找不到application或者找不到activity的错误(java.lang.ClassNo ...

  6. 动态规划——最长公共子序列&&最长公共子串

      最长公共子序列(LCS)是一类典型的动归问题. 问题 给定两个序列(整数序列或者字符串)A和B,序列的子序列定义为从序列中按照索引单调增加的顺序取出若干个元素得到的新的序列,比如从序列A中取出 A ...

  7. go练习1-翻转字符串

    //翻转字符串 func T1_1() { str := "你好helloworld!" fmt.Println("翻转前", str) var ret str ...

  8. 170414、zookeeper和dubbo的关系

    Dubbo建议使用Zookeeper作为服务的注册中心. 1.   Zookeeper的作用:         zookeeper用来注册服务和进行负载均衡,哪一个服务由哪一个机器来提供必需让调用者知 ...

  9. CSS样式表、JS脚本加载顺序与SpringMVC在URL路径中传参数与SpringMVC 拦截器

    CSS样式表和JS脚本加载顺序 Css样式表文件要在<head>中先加载,这样网页显示时可以第一次就渲染出正确的布局和样式,网页就不会闪烁,或跳变 JS脚本尽可能放在<body> ...

  10. Sass之二(进阶篇)

    源码链接:http://pan.baidu.com/s/1o8M51hC 1. 数据类型 1.1 Number 数字类型,小数类型,带有像素单位的数字类型,全部都属于Number类型 Number类型 ...