【HDU5783】Divide the Sequence(贪心)
来源:互联网 发布:linux环境变量配置 编辑:程序博客网 时间:2024/05/19 06:35
记录一个菜逼的成长。。
Divide the Sequence
把长度为n的序列分成尽量多的连续段,使得每一段的每个前缀和都不小于0。保证有解。 从后往前贪心分段即可。
/(ㄒoㄒ)/~~
#include <cstdio>#include <cstring>typedef long long LL;const int maxn = 1000000 +10;LL sum[maxn];int main(){ int n; while(~scanf("%d",&n)){ memset(sum,0,sizeof(sum)); for( int x,i = 1; i <= n; i++ ){ scanf("%d",&x); sum[i] = sum[i-1] + x; } int ans = 0; LL tmp = sum[n]; for( int i = n; i > 0; i-- ){ if(tmp - sum[i-1] >= 0 && sum[i-1] >= 0){ ans++; tmp = sum[i-1]; } } printf("%d\n",ans); } return 0;}
0 0
- 【HDU5783】Divide the Sequence(贪心)
- HDU5783 Divide the Sequence(贪心)
- HDU5783(2016多校第五场)——Divide the Sequence(水水水)
- 2016多校训练Contest5: 1003 Divide the Sequence hdu5783
- HDOJ 5783 Divide the Sequence(贪心)
- 【HDOJ5783】Divide the Sequence(贪心)
- HDU 5783 Divide the Sequence(贪心)
- HDU5783 - Divide the Sequence(2016 Multi-University Training Contest 5 - C)
- HDU-5783 Divide the Sequence(贪心水题)
- HDU 5783 Divide the Sequence 【贪心】
- 【贪心】HDU 5783 Divide the Sequence
- 2016 Multi-University Training Contest 5 1003 Divide the Sequence (贪心)
- 2016多校5 hdu 5783 Divide the Sequence 贪心
- HDU 5783 Divide the Sequence——贪心
- HDU 5783 Divide the Sequence(水题)
- Divide the Sequence
- Divide the Sequence
- Divide the Sequence
- List与Set的基础知识
- 可视化工具--D3--案例分析--Chord Diagram
- IONIC WebApp之tabs框架样式修改
- 大数据系列修炼-Scala课程04
- PAT 乙级1014. 福尔摩斯的约会(C语言版)
- 【HDU5783】Divide the Sequence(贪心)
- Python 2-3的坑
- 文章标题
- UVA 11270 Tiling Dominoes(用1×2骨牌覆盖n×m棋盘,有多少种方法)
- 转载一篇个人觉得不错的关于对象引用的文章
- 生成Description
- BC#86.1002(HDOJ5805)NanoApe Loves Sequence
- 位运算及其应用详解
- 读书与思考