• YTU 2902: H-Sum 3s


    2902: H-Sum 3s

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 139  解决: 28

    题目描述

    You are given a number sequence a1,a2,a3...,an , your task is to find if there is a pair of interger (i,j) that ai+a(i+1)+..+aj equals to 0 and i<=j;

    输入

    Input consists of multiple test cases. For each case, the first line of input contains an integer n, the next line follows n integers. (n>=1 && n<=10^5 |ai|<=10^4)

    输出

    For each case, if there is at least one pair of integer (i,j) meet the requirement, print “YES”, otherwise print “NO” .

    样例输入

    51 2 3 4 553 4 -2 -3 1

    样例输出

    NOYES

    im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......可怜

    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main()
    {
        int N;
        while (cin>>N)
        {
            int i,k=0,a[100000],s[100000];
            cin>>a[0];
            s[0]=a[0];
            if (a[0]==0)
                k=1;
            for (i=1; i<N; i++)
            {
                cin>>a[i];
                s[i]=s[i-1]+a[i];
                if (a[i]==0||s[i]==0)
                    k=1;
            }
            if (k==0)
            {
                sort(s,s+N);
                for (i=0; i<N-1; i++)
                    if (s[i]==s[i+1])
                    {
                        k=1;
                        break;
                    }
            }
            if (k==1)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
     
        }
        return 0;
    }


  • 相关阅读:
    Fruit HDU
    排列组合 HDU
    XOR and Favorite Number CodeForces
    BZOJ-6-2460: [BeiJing2011]元素-线性基
    CDH 安装与部署
    Apache Hadoop集群搭建
    大数据架构与技术选型
    项目落实方案选择思考(KUDU)
    JAVA 高级篇
    大数据就业岗位
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989667.html
Copyright © 2020-2023  润新知