zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 31 B. Japanese Crosswords Strike Back【暴力】

    B. Japanese Crosswords Strike Back
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.

    For example:

    • If x = 6 and the crossword is 111011, then its encoding is an array {3, 2};
    • If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1};
    • If x = 5 and the crossword is 11111, then its encoding is an array {5};
    • If x = 5 and the crossword is 00000, then its encoding is an empty array.

    Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!

    Input

    The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked.

    The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.

    Output

    Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.

    Examples
    input
    2 4
    1 3
    output
    NO
    input
    3 10
    3 3 2
    output
    YES
    input
    2 10
    1 3
    output
    NO
    【题意】:给了段数和长度,以及每一段的长度,问是否只有唯一一种情况,只要满足a1+a2+...+an=x-n+1即可
    【分析】:rt
    【代码】:
    #include <bits/stdc++.h>
    
    using namespace std;
    #define inf 1e18+100
    #define LL long long
    
    const int maxn = 1e5+100;
    
    int main()
    {
        int n,m,sum;
        int a[maxn];
        while(cin>>n>>m)
        {
            sum=0;
            for(int i=0;i<n;i++)
            {
                cin>>a[i];
                sum+=a[i];
            }
            if(sum==m-n+1)
                puts("YES");
            else
                puts("NO");
        }
    }
    View Code
  • 相关阅读:
    UNIT THREE
    UNIT TWO
    UNIT ONE
    实验九 根据材料编程
    实验五 编写、调试具有多个段的程序
    实验 四 [bx]和loop的使用
    实验二 用机器指令和汇编指令编程
    实验三 编程、编译、连接、跟踪
    实验一 查看CPU和内存,用机器指令和汇编指令编程
    汇编语言第5~8章知识总结
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7781042.html
Copyright © 2011-2022 走看看