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 ...
随机推荐
- linux之pid文件
在命令行中经常看到*.pid文件 其实这些文件是在启动进程的时候系统给这个进程的master进程分配的进程号 比如/usr/local/nginx/logs/nginx.pid文件 打开这个文件会发现 ...
- 排序算法总结(一)插入排序【Insertion Sort】
最近在忙着找工作,以前看的排序算法都忘记了,悲剧啦T T现在来回顾一下吧. 这边推荐一个算法可视化的网站,非常有用.http://visualgo.net/ 一.插入排序的思想(Wikipedia) ...
- Linux 的账号与群组[转自vbird]
Linux 的账号与群组 管理员的工作中,相当重要的一环就是『管理账号』啦!因为整个系统都是你在管理的, 并且所有一般用户的账号申请,都必须要透过你的协助才行!所以你就必须要了解一下如何管理好一个服务 ...
- JQuery之滑动幻灯片插件Easy Slider初体验
Easy Slider 是一个滑动幻灯片插件,支持任何图片或内容,可以实现横向或纵向滑动.它拥有一系列丰富的参数设置,可通过CSS来进行完全的控制.基本上只需要引入这个插件后,设置好内容,然后样式化C ...
- m3u8文件简介
1. M3U8文件概念 M3U8文件是指UTF-8编码格式的M3U文件.M3U文件是记录了一个索引纯文本文件,打开它时播放软件并不是播放它,而是根据它的索引找到对应的音视频文件的网络地址进行在线播 ...
- 通过 Javacore 诊断线程挂起等性能问题
http://www.ibm.com/developerworks/cn/websphere/library/techarticles/1406_tuzy_javacore/1406_tuzy_jav ...
- Xcode 7 ImageNamed 方法加载jpg图片失败
更新XCode7后 原来的Image.xcassets文件夹变成了Assets.xcassets 把01.jpg,02.jpg,03.png拖入这个文件夹中 UIImage* test1=[UIIma ...
- PHP获得两个绝对路径的相对路径
周末在家看面试题,没事儿写了个. 题目: 写一个函数,算出两个文件的相对路径 如 $a = '/a/b/c/d/e.php'; $b = '/a/b/12/34/c.php';计算出 $b 相对于 $ ...
- 09-Java 工程结构管理
(一)Java 工程结构管理 1.什么是Build Path: -- 一般包括:JRE运行时库 第三方功能扩展库(*.jar 格式文件) 其他的工程 其他的源代码或Class 文件 为什么使用~ :通 ...
- 【转】Deprecated: Function ereg_replace() is deprecated的解决方法
这个问题是因为你用的php版本过高. 在php5.3中,正则函数ereg_replace已经废弃,而dedecms还继续用.有两个方案可以解决以上问题: 1.把php版本换到v5.3下. 2.继续使用 ...