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

YTU 2902: H-Sum 3s的更多相关文章

  1. YTU 2905: The Sum of 1...N

    2905: The Sum of 1...N 时间限制: 1 Sec  内存限制: 128 MB 提交: 281  解决: 51 题目描述 Given an integer n,your task i ...

  2. URAL 1146 Maximum Sum 最大子矩阵和

    题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...

  3. Uva10290 - {Sum+=i++} to Reach N

    Problem H {sum+=i++} to Reach N Input: standard input Output:  standard output Memory Limit: 32 MB A ...

  4. [leetcode-560-Subarray Sum Equals K]

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  5. 给定n个数字,问能否使这些数字相加得到h【折半查找/DFS】

    A Math game Time Limit: 2000/1000MS (Java/Others) Memory Limit: 256000/128000KB (Java/Others) Submit ...

  6. PAT 1049. 数列的片段和(20)

    给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1 ...

  7. Mysql 常用 SQL 语句集锦

    Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...

  8. POJ 3233Matrix Power Series

    妈妈呀....这简直是目前死得最惨的一次. 贴题目: http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS Mem ...

  9. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

随机推荐

  1. luogu4093 [HEOI2016/TJOI2016]序列

    因为一个变化只会变化一个值,所以 \(dp[i]=max(dp[j])+1,j<i,maxval_j \leq a[i], a[j] \leq minval_i\) 发现跟二维数点问题挺像,树状 ...

  2. js中的constructor 和prototype

    参考 http://www.cnblogs.com/yupeng/archive/2012/04/06/2435386.html function a(c){ this.b = c; this.d = ...

  3. 大数据学习——hdfs客户端流式操作代码的实现

    package cn.itcast.bigdata.hdfs.diceng; import org.apache.hadoop.conf.Configuration; import org.apach ...

  4. Personal Recommendation Using Deep Recurrent Neural Networks in NetEase读书笔记

    一.文章综述 1.研究目的:实现网易考拉电商平台的商品高效实时个性化推荐.缩短用户与目标商品的距离,让用户点击最少的页面就可以得到想要的商品 2.研究背景:基于用户和基于物品的协同过滤(Collabo ...

  5. C# CreateDataTable

    public DataTable CreateDataTable()         {             DataTable dataTable = new DataTable();      ...

  6. python学习之-- socketserver模块

    socketserver 模块简化了网络服务器的编写,主要实现并发的处理. 主要有4个类:这4个类是同步进行处理的,另外通过ForkingMixIn和ThreadingMixIn类来支持异步.sock ...

  7. (二)Commonjs规范与模块化

    在之前的学习中我们使用require()来引入我们需要的包,这其实就是模块化,各模块相互独立,可以通过某种方式引入别的模块.而这些引入方式都是遵循一定的规范的,这就是CommonJS规范. 一.Com ...

  8. 使用微软的 ilasm 和 ildasm 对. net程序进行编译和反编译

    为了保证示例的完整性,请先准备好一个 c#写的 exe 程序,或者可以使用我提供的 exe 程序也可以(很简单,为了测试这里仅生成了一个带按钮的 winform,单击按钮提示弹窗) Test WinF ...

  9. ArcGIS中Shapefile和Geodatabase坐标容差的问题

    转自原文 ArcGIS中Shapefile和Geodatabase坐标容差的问题 ArcGIS中,Shapefile文件是没有容差设置的,所以无论什么单位的坐标写入shapefile文件,都不存在容差 ...

  10. CentOS7 设置系统时间

    在CentOS 6版本,时间设置有date.hwclock命令, 硬件时钟和系统时钟 (1) 硬件时钟 RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会 ...