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. P5162 WD与积木(多项式求逆+生成函数)

    传送门 题解 比赛的时候光顾着算某一个\(n\)的答案是多少忘了考虑不同的\(n\)之间的联系了--而且我也很想知道为什么推着推着会变成一个二项式反演-- 设\(f_n\)为\(n\)块积木时的总的层 ...

  2. touch的基本用法

    touch的基本功能是改变文件的时间戳,以下是三种常用用法: 1.创建一个空文件 以当前时间为时间戳创建一个空文件.$ touch touch.txt //touch.txt不存在 2.更改文件时间戳 ...

  3. iOS Swift3 用全局“宏”时要注意的问题

    当你需要定义一个APP全局“宏”来调用 UserDefaults.standard里存储的值的时候, 一定要将这个“宏”定义为计算属性,否则你得到的值只会在APP启动的时候计算一次. 示例如下: va ...

  4. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    考场上只做出了ABDE C都挂了... 题解: A 题解: 模拟 判断前面一段是否相同,后面一段是否相同,长度是否够(不能有重叠) Code: #include<stdio.h> #inc ...

  5. Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)

    题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果 ...

  6. Educational Codeforces Round 20 B

    Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...

  7. debug授权码

    www.vfxcx.com 704835b5c54b56426257e0742568fe54

  8. 降低winnt Apache服务的权限,让你的虚拟主机更安全

    winnt 安装 Apache 后,在后台的服务默认是以system权限运行的(system是winnt的最高权限),这给服务器带来很大的安全隐患,最近我遇到的就是php的W8C 文件管理既然可以随意 ...

  9. AJPFX关于java中可访问控制符和非访问控制符的详细总结

    1.类的修饰符分为:可访问控制符和非访问控制符两种. 可访问控制符是:公共类修饰符 public 非访问控制符有:抽象类修饰符 abstract :最终类修饰符 final 1 )公共类修饰符 pub ...

  10. 字符串、数组、json

    一.字符串 string 1.字符串的定义: (1).var s="haha"; (2).var s=new string ("hello") 对象形式定义 2 ...