Divide the Sequence

题意:

给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0

题解:

这题是比赛时候的水题,但我比的时候也就做出这一题, = =

首先我想的是把他们前缀和求出来,之后试了下样例,一点鸟用都没有,那正着不行就倒着试下呗,之后发现这样有用,我先想到的思路是求后缀和,只要>=0就ans++,但那时队友举出了反例,比如2 1 -3 3的时候应该是2,我的算法就是4,那接着马上就能想到如果后缀和大于0,那么就要把他赋为0,之后举了几组例子,没问题,写了几分钟,之后1A。

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
#define PI(A) cout<<A<<endl
#define SI(N) cin>>N
#define SII(N,M) cin>>N>>M
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
#define dbg(x) cout <<#x<<" = "<<x<<endl
#define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
#define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
const double EPS= 1e-9 ; /* ///////////////////////// C o d i n g S p a c e ///////////////////////// */ const int MAXN= 1000000 + 9 ; ll a[MAXN];
int N; int main()
{
iostream::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
while(SI(N))
{
ll ans=0;
rep(i,N) SI(a[i]);
ll sum=0;
reRep(i,N-1,0)
{
sum+=a[i];
if (sum>=0) sum=0;
if (sum==0) ans++;
}
PI(ans);
}
return 0;
}

2016 Multi-University Training Contest 5 Divide the Sequence的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2015 Multi-University Training Contest 1 OO’s Sequence

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  4. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  5. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  6. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  7. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  8. 2016 Al-Baath University Training Camp Contest-1 G

    Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...

  9. 2016 Al-Baath University Training Camp Contest-1 F

    Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...

随机推荐

  1. spark新能优化之序列化的持久化级别

    除了对多次使用的RDD进行持久化操作之外,还可以进一步优化其性能.因为很有可能,RDD的数据是持久化到内存,或者磁盘中的.那么,此时,如果内存大小不是特别充足,完全可以使用序列化的持久化级别,比如ME ...

  2. 《笨办法学Python》

    习题一 第一个程序 print "Hello World!" print "Hello Evilxr" print "I like typing th ...

  3. js获取客户端操作系统

    function detectOS() { var sUserAgent = navigator.userAgent; var isWin = (navigator.platform == " ...

  4. php mcrypt 完全安装

    今天安装完 PHP ,访问某个功能时,  /var/log/httpd/error_log  中报如下错误: PHP Fatal error:  Call to undefined function ...

  5. QAction类详解:

    先贴一段描述:Qt文档原文: Detailed Description The QAction class provides an abstract user interface action tha ...

  6. Sublime Text 下配置python

    Sublime Text 2作为一款轻量级的编辑器,特点鲜明,方便使用,而且支持多语言.  一.control+B方式 1. 在工具栏点击Preferences,打开Browse Packages.在 ...

  7. 当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误

    当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示. 有两种方法可以解决以上问题: 1.修改we ...

  8. openjudge-回文串判断【递归】

    回文串判断 总时间限制: 1000ms 内存限制: 65536kB 描述 任意给定一个非空的字符串,判断其是否是回文串.回文串是指正向看和反向看均相等的串,如AbcDcbA和cDDc.如果是回文串,则 ...

  9. innodb数据库批量转换表引擎为MyISAM

    2013.0106 innodb数据库批量转换表引擎为MyISAM 来源:本站原创 PHP, 数据库, 系统技术 超过488名童鞋围观 1条评论  <?php //连接数据库 $host='lo ...

  10. .NET和java的RSA互通,仅此而已

    .NET和java的RSA互通,仅此而已 在开始这篇文章之前,先请读者朋友阅读老唐的这两篇文章: 1.Java与.Net环境下RSA加密解密交互不成功的问题解决 2.Java与.Net环境下RSA加密 ...