CF519 ABCD D. A and B and Interesting Substrings(map,好题)
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,好题)的更多相关文章
- [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...
- 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 ...
- 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 ...
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
题意: 对于26个字母 每个字母分别有一个权值 给出一个字符串,找出有多少个满足条件的子串, 条件:1.第一个字母和最后一个相同,2.除了第一个和最后一个字母外,其他的权和为0 思路: 预处理出sum ...
- cf519D . A and B and Interesting Substrings 数据结构map
题意: 已知26个小写字母有各自的权值(正,负,或0) 现在给出一个字符串,长度<=1e5 问这个字符串有多少个子串满足: 开头的字母和结尾的字母一样 字符串除了开头和结尾的字母外,其余的字母的 ...
- Codeforces 519D A and B and Interesting Substrings(二维map+前缀和)
题目链接:http://codeforces.com/problemset/problem/519/D 题目大意:给你一串字符串s仅由小写字母组成,并且对于'a'~'z'都给了一个值.求子串t满足t的 ...
- cf519D. A and B and Interesting Substrings(前缀和)
题意 给出$26$个字母对应的权值和一个字符串 问满足以下条件的子串有多少 首尾字母相同 中间字母权值相加为0 Sol 我们要找到区间满足$sum[i] - sum[j] = 0$ $sum[i] = ...
- CodeForces 519D A and B and Interesting Substrings ——(奥义字符串)
题意:给出26个字母每个字母的价值,问字符串中有多少个满足以下条件的子串: 1.子串的第一个和最后一个相同 2.子串除了头和尾的其他字符的价值加起来和尾0 这题普通方法应该是O(n^2),但是在1e5 ...
- Spring IoC介绍与Bean的使用
1. 介绍 IoC IoC-Inversion of Control,即"控制反转",它不是什么技术,而是一种设计思想.在 Java 开发中, IoC意味着将设计好的对象交给容 ...
随机推荐
- python的zipfile实现文件目录解压缩
主要是 解决了压缩目录下 空文件夹 的压缩 和 解压缩问题 压缩文件夹的函数: # coding:utf- import os import zipfile def zipdir(dirToZip,s ...
- 为什么逻辑斯特回归(logistic regression)是线性模型
一个典型的logistic regression模型是: 这里明明用了非线性函数,那为什么logistic regression还是线性模型呢? 首先,这个函数不是f(y,x)=0的函数,判断一个模型 ...
- 004杰信-关于formSubmit('factorycreate.action','_self')路径的疑惑
本文材料来源于传智播客,在此说明. 整个项目结构:
- 开启mysql日志及若干问题
今天学习了mysql日志功能,以前也有所了解,只不过没有深入的学习,所以趁着“余热”,把我从网上找到的资料与实践 结合起来,总结一下其基本用法.学习从来都不是无趣的,就看你怎么看待学习. 1.查看查询 ...
- ThinkPHP无限级分类
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ ...
- COCOS2D-X多层单点触摸分发处理方案?
如今的问题是点击button的时候,会触发底层的触摸事件,怎么不触发底层的触摸事件啊?
- Hibernate_day02--课程安排_主键生成策略_对实体类crud操作_实体类对象状态
Hibernate_day02 上节内容 今天内容 实体类编写规则 Hibernate主键生成策略 实体类操作 对实体类crud操作 添加操作 根据id查询 修改操作 删除操作 实体类对象状态(概念) ...
- 遇到OutOfMemoryException异常了
遇到OutOfMemoryException异常了 2008-11-28 09:52 asp.net做的售后服务系统运行了快1年了,昨天在做全年数据导出的时候出现OutOfMemoryExceptio ...
- iOS消息推送证书创建过程
iOS消息推送证书创建过程 一.创建证书请求 1.在mac上进行钥匙串访问(keychain) 2. 选择钥匙串访问>证书助理> 从证书颁发机构中请求一个证书,如图1所示 图1 3.输入你 ...
- WEB状态码
这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个 1xx 响应. 100 - 继续. 101 - 切换协议. 2xx - 成功 这类状态代码表明服务器成功地接受了客户端请求. ...