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意味着将设计好的对象交给容 ...
随机推荐
- SSIS 自测题-数据流控件类
说明:以下是自己的理解答案,不是标准的答案,如有不妥烦请指出. 有些题目暂时没有答案,有知道的请留言,互相学习,一起进步. 133.请描述一下 Conditional Split 的使 ...
- javascript弹出层-DEMO001
首先上一张图 看下弹出层的效果 从图中可以看到二部分 一是弹出层 二是遮照层 弹出层:即弹出你要操作的内容 遮照层:遮照住不要操作的内空 实际技术原理主要是 CSS +JS (z-index是核心) ...
- 关于JQueryMobile中Slider的一点研究
滑动条 Slider 给input的设置一个新的HTML5属性为type="range",可以给页面添加滑动条组件,可以指定它的value值(当前值 ...
- CSS:scrollbar的属性及样式分类
overflow 内容溢出时的设置(设定被设定对象是否显示滚动条) overflow-x 水平方向内容溢出时的设置 overflow-y 垂直方向 ...
- 【vijos】1164 曹冲养猪(中国剩余定理)
https://vijos.org/p/1164 好赞orz. 对于求一组线性同余方程 x=a[i](mod m[i]) 这里任意两个m[i]和m[j]都互质 那么可以用中国剩余定理来做. 对中国剩余 ...
- bootstrap基础学习三篇
bootstrap的排版 1.标题 Bootstrap 中定义了所有的 HTML 标题(h1 到 h6)的样式 2.代码如下: <div class="container"& ...
- mysql的优化基础知识
1.查看各种SQL执行的频率 mysql> show status like 'Com_select';--Com_insert,Com_delete,connections(试图连接mysql ...
- SQL UNIQUE Constraint
SQL UNIQUE Constraint The UNIQUE constraint uniquely identifies each record in a database table. The ...
- linux 远端执行shell脚本 批量结束各个远端节点进程
#以下是一个本地的shell脚本,用于同时重启远端多台服务器tomcat服务 #!/bin/sh# ancyshi 重新启动节点tomcat服务function restartNodeTomcatSe ...
- RMI几种公布和引用服务的方式
RMI是Java原生的分布式服务机制.支持Java对Java的分布式訪问.採用Java的序列化协议进行CodeC操作. 这里简单说下RMI公布服务和client引用服务的方式. RMI公布服务时支持两 ...