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. ubuntu 给文件夹创建桌面快捷方式, 其实就是创建个软链接

    ln -s /home/zdj/Documents/windows_backup/2019Spring/ ~/Desktop/2019Spring ln -s /home/zdj/Documents/ ...

  2. Springboot配置类

    配置类 MyAppConfig  import com.test.springboot.service.HelloService; import org.springframework.context ...

  3. Java自定义方法转换前端提交的json字符串为JsonObject对象

    前端提交json字符串格式数据,Java后端通过自定义方法接收json字符串数据并转换为JsonObject对象,代码如下放到RequestData.Java类中: public static JSO ...

  4. UWP 动画

    一:StoryBoard 一般翻译成演示图版或者故事板,就像电影中的情节串联板,它是一个动画时间线的容器. 二:动画的分类       简单动画:以Animation结尾,例如DoubleAnimat ...

  5. HDU6438(贪心技巧)

    第一眼喜闻乐见的股票问题dp可以暴力,然鹅时间不允许. 于是考虑怎么贪. 这篇题解说得很生动了. 因为每支股票都有买入的潜力所以肯定都加在优先队列里. 然后考虑的是哪些需要加入两次.这是我第二次见到类 ...

  6. PDO相关函数

    (PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0) PDO::__construct — 创建一个表示数据库连接的 PDO 实例 说明 PDO::__co ...

  7. Visual Studio Code配置 HTML 开发环境

    Visual Studio Code配置 HTML 开发环境 https://v.qq.com/x/page/l0532svf47c.html?spm=a2h0k.11417342.searchres ...

  8. [转]写给Git初学者的7个建议

    本文转自:http://www.open-open.com/news/view/b7227e 阅读目录 第一条:花时间去学习 Git 的基本操作 第二条:从简单的 Git 工作流开始 第四条:理解分支 ...

  9. 《Redis开发与运维》快速笔记(一)

    1.前言&基本介绍 在原始的系统架构中,我们都由程序直接连接DB,随着业务的进一步开展,DB的压力越来越大,为了缓解DB的这一压力,我们引入了缓存,在程序连接DB中加入缓存层, 从而减轻数据库 ...

  10. lock和synchronized的同步区别与选择

    1. lock是一个接口,而synchronized是java的一个关键字,synchronized是内置的语言实现:(具体实现上的区别在<Java虚拟机>中有讲解底层的CAS不同,以前有 ...