B. Intercepted Message
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive. Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages. You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct. Input
The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106. Output
Print the maximum number of files the intercepted array could consist of. Examples
inputCopy
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8
output
3
inputCopy
3 3
1 10 100
1 100 10
output
2
inputCopy
1 4
4
1 1 1 1
output
1
Note
In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100. In the third example the only possibility is that the archive contains a single file of size 4.

既然要保证序列顺序不变,那么前缀和就具备各种优良的性质了。

//Stay foolish,stay hungry,stay young,stay simple
#include<iostream>
using namespace std; const int MAXN=100005; int lena,lenb;
int a[MAXN],b[MAXN];
int sa[MAXN],sb[MAXN];
bool vis[MAXN*10];
int main(){
cin>>lena>>lenb;
for(int i=1;i<=lena;i++){
cin>>a[i];
sa[i]=sa[i-1]+a[i];
}
for(int i=1;i<=lenb;i++){
cin>>b[i];
sb[i]=sb[i-1]+b[i];
}
for(int i=1;i<=lena;i++) vis[sa[i]]=1;
int ans=0;
for(int i=1;i<=lenb;i++) {
if(vis[sb[i]]) ans++;
}
cout<<ans<<endl;
return 0;
}

[CF] 950B Intercepted Message的更多相关文章

  1. 469 B. Intercepted Message

    http://codeforces.com/problemset/problem/950/B Hacker Zhorik wants to decipher two secret messages h ...

  2. 题解 CF950B 【Intercepted Message】

    题目链接 先吐槽一番:本宝宝好久没写过题解了...首先我们想一个贪心策咯.就是我们预处理出前缀和,然后一边扫过去,记录一个l1,l2和一个n1,n2.分别表示我们现在第一个数组切到l1,上一次切是在n ...

  3. 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)

    剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...

  4. ACM 第七天

    水题 B - Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair ...

  5. Apache Mina -2

    我们可以了解到 mina是个异步通信框架,一般使用场景是服务端开发,长连接.异步通信使用mina是及其方便的.不多说,看例子. 本次mina 使用的例子是使用maven构建的,过程中需要用到的jar包 ...

  6. Codeforces Round #469 Div. 2 A B C D E

    A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...

  7. Codeforces Round #469 Div. 2题解

    A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...

  8. 深入理解netty---从偶现宕机看netty流量控制

    一.业务背景 目前移动端的使用场景中会用到大量的消息推送,push消息可以帮助运营人员更高效地实现运营目标(比如给用户推送营销活动或者提醒APP新功能). 对于推送系统来说需要具备以下两个特性: 消息 ...

  9. java8中CompletableFuture的使用介绍

    既然CompletableFuture类实现了CompletionStage接口,首先我们需要理解这个接口的契约.它代表了一个特定的计算的阶段,可以同步或者异步的被完成.你可以把它看成一个计算流水线上 ...

随机推荐

  1. PTA【复数相乘】

    队友在比赛时A掉的.吊吊吊!!! 主要考虑这些情况吧||| 案例: /* 3i i -3 i -1-i 1+i i 1 -1-i -1-i */ -3 -3i -2i i 2i #include &l ...

  2. PTA 水...

    习题4-2 求幂级数展开的部分和 (20分) 已知函数e^x可以展开为幂级数1+x+x2/2!+x3/3!+⋯+xk/k!+⋯1+x+x^2 /2! + x^3 /3! + \cdots + x^k ...

  3. vue父组件调用子组件方法

    父组件: 代码 <sampleapplylinemodel ref="sampleapplylinemodel" @reLoad="_fetchRecords&qu ...

  4. .NET Core 跨平台物联网开发:设置委托事件(二)

    系列教程目录 (一) 连接阿里云IOT (二) 设置委托事件 (三) 上报属性 (四)  SDK文档 属性.方法.委托.类 http://pan.whuanle.cn/index.php?dir=up ...

  5. Centos 6.8 配置Lvs

    LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. 宗旨: 使 ...

  6. spring mvc No mapping found for HTTP request with URI [/web/test.do] in DispatcherServlet with name 'spring'

    原因: spring-servlet.xml 中 <context:component-scan base-package="com.test.controller" /&g ...

  7. The 17th Zhejiang University Programming Contest Sponsored by TuSimple J

    Knuth-Morris-Pratt Algorithm Time Limit: 1 Second      Memory Limit: 65536 KB In computer science, t ...

  8. java 替换字符串模板(模板渲染)

    java渲染字符串模板,也就是说在java字符串模板中设置变量字符串,使用变量去渲染指定模板中设置好的变量字符串.下面介绍4种替换模板方式: 1.使用内置String.format String me ...

  9. logging模块进阶2

    1.两种级别设置: 全局级别:生成logger对象后设置的级别 局部级别:生成handler对象设置的级别 我们都知道输出的级别不能低于设定的级别,那么全局级别和局部级别哪一个对输出产生影响? 经过多 ...

  10. 【学习笔记】彻底理解JS中的this

    首先必须要说的是,this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁,实际上this的最终指向的是那个调用它的对象(这句话有些问题,后面会解释为什么会有问题,虽然 ...