zoukankan      html  css  js  c++  java
  • [CF] 950B Intercepted Message

    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;
    }

    本文来自博客园,作者:GhostCai,转载请注明原文链接:https://www.cnblogs.com/ghostcai/p/9247458.html

  • 相关阅读:
    开发win8 metro monogame,显示pubcenter广告时会使游戏卡住的问题的解决方法。
    win8商店应用验证,二进制文件是在调试模式下生成的解决方案。
    slxna,游戏页面切到后台回来后返回sl页面导致sl页面无响应,解决方法。
    支持虚拟化也开来虚拟化就是装不上HyperV的解决方法
    WP中一些耗时的东西
    WP自定义字体
    SystemTray文字颜色问题
    longlistselector 闪烁问题研究
    vs2013安装xna4.0模板
    让textbox紧贴IME
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247458.html
Copyright © 2011-2022 走看看