2016 Multi-University Training Contest 5 Divide the Sequence
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的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 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 ...
- 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 ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- kafka的推和拉的问题
之前学习过这一问题,但是面试又被问道了.再次记录下 推还是拉? Kafka最初考虑的问题是,customer应该从brokes拉取消息还是brokers将消息推送到consumer,也就是pull还p ...
- scala言语基础学习十二
- phpwind8.7升级9.0.1过程(三)20130107升级到20130227
升级之前一定要备份以下内容 1.网站根目录所有文件 2.网站数据库 在升级到20130227版本的时候出现以下问题. 问题: 问题原因:本地服务器不支持fsockopen()函数,此函数需要开启,但是 ...
- Android ——Handler相关
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- MySql中的skip-name-resovle
mysql用的一直很好用,有一次断网了,发现连接虚拟机里的mysql特别费劲,几经扔腾,才知道是因为断网以后,名字解析这块有点问题,在my.cnf文件中加了一条skip-name-resovle,果断 ...
- sqlite3编程使用简介
sqlite3使用范围 SQLite不同于其他大部分的SQL数据库引擎,因为它的首要设计目标就是简单化: 1.易于管理 2.易于使用 3.易于嵌入其他大型程序 4.易于维护和配置 许多人喜欢SQLi ...
- [转]easyui常用控件及样式API中文收藏
[转]easyui常用控件及样式收藏 2013-05-06 23:01 30612人阅读 评论(0) 收藏 举报 分类: java ee(5) 目录(?)[+] CSS类定义: div easyu ...
- Asp.net中全局缓存的几种方式
public class StaticCacheTest { private static IDictionary<string, object> _dic; private static ...
- [oracle] 设置PL/SQL Developer 字符集
我安装的是PLSQL Developer(10)执行SQL发现弹出的错误提示对话框都是??表示,显示不出正确的提示信息.后来才明白是跟服务器的字符集不匹配的问题.方法如下:1.查询oracle ser ...
- CSS命名规则
头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中:le ...