Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现Problem H: H-Sum 3s
2015-04-10 19:20
531 查看
Problem H: H-Sum 3s
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 77 Solved: 10
[Submit][Status][Web
Board]
Description
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
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)Output
For each case, if there is at least one pair of integer (i,j) meet the requirement, print “YES”, otherwise print “NO” .Sample Input
51 2 3 4 553 4 -2 -3 1
Sample Output
NOYES
HINT
AC代码:#include <iostream> using namespace std; int main(){ int n; while(cin>>n){ int a ; int sum=0,i=0,k=0,s1,t1,t2,j;; while(i<n){ cin>>a[i]; sum+=a[i]; if(a[i]==0||sum==0)k++; if(k==0){ for(j=0,t2=0;j<i-1;j++){ t1=a[j]; t2+=t1; s1=sum-t2; if(s1==0){ k++; break; } } } i++; } if(k==0) cout<<"NO"<<'\12'; else cout<<"YES"<<'\12'; } return 0; }
运行结果:
心得:
这看起来是一道很简单的题,2个循环就出来了。但如果这样oj平台会给出时间超限的提示。所以要想办法减少计算时间,我是在输入数据的同时完成部分运算。谢天谢地在错误9次后终于ac了。感觉棒!
相关文章推荐
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现Problem C: C-Z型变换
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现 A--A Repeating Characters
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现F-A Simple Question
- Contest1376 - "师创杯"烟台大学第二届ACM程序设计精英赛复现 B--Faultfinding
- 程序设计模式之"监听器模型"
- 第二届"春回燕归 浙籍精英峰会"见闻
- 身份证校验 如果让你设计个程序,用什么变量保存身份证号码呢?长整数可以吗?不可以! 因为有人的身份证最后一位是"X"
- 利用ftp服务程序本身设计的"缺陷"取得最高权限
- Max Sum &&http://acm.hdu.edu.cn/showproblem.php?pid=1003
- acm/icpc中国 辽宁省第二届大学生程序设计竞赛结束了
- 2001-2002 ACM Northeastern European Regional Programming Contest-Problem G-"Library"
- 未能在"设计"视图中打开.在""块中,以不同方式将值括起来的解决方案汇总
- (小常识)为什么程序中不能使用system("cd ..")来改变pwd(present working directory)
- "hello,world!"win32汇编小程序
- "某个程序安装已在安装计算机上创建挂起的文件操作" 解决办法 另解
- "某个程序安装已在安装计算机上创建挂起的文件操作" 解决办法 另解
- SQLServer2000的"以前的某个程序安装已在安装计算机上创建挂起的文件操作。运行安装程序之前必须重新启动计算机"错误
- 打开文件->选择程序 出现"拒绝访问"
- 升级IE弹出"以前的安装有尚未完成的操作,需要重新启动。建议在运行Internet Explorer安装程序之前重新启动计算机。现在安装程序将关闭"
- 安装Visual Studio 6的"Error Lauching acmboot.exe"问题解决方法