【HDOJ5783】Divide the Sequence(贪心)
来源:互联网 发布:js获取外部css样式 编辑:程序博客网 时间:2024/05/06 03:37
记录一个菜逼的成长。。
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
- 【HDOJ5783】Divide the Sequence(贪心)
- 2016多校5 hdoj5783 Divide the Sequence
- HDOJ 5783 Divide the Sequence(贪心)
- 【HDU5783】Divide the Sequence(贪心)
- HDU 5783 Divide the Sequence(贪心)
- HDU5783 Divide the Sequence(贪心)
- 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
- hdu 5783 Divide the Sequence
- Divide the Sequence hdu 5783
- HDU 1166 敌兵布阵 树状数组
- GetWindowRect,GetClientRect,ScreenToClient MoveWindow SetWindowPos 用法说明
- c调用c++编的dll,c++调用c编写的dll,extern “C”的用法
- Spark优化及总结
- android中通过添加view使用ViewPager出现的问题及解决方法
- 【HDOJ5783】Divide the Sequence(贪心)
- C++链表的创建与操作
- 门户、论坛、博客、SNS,网站模式的辨析
- 【一步一步学习VBA】Excel VBA 获取指定单元格的数据并进行字符串匹配
- Mysql用Navicat和Workbench导入导出数据库表
- Windows NT 的 TCP/IP 路由基础
- 关于display: inline-block 默认空白间距的问题
- Elasticsearch搜索入门
- 安卓手机定位,location为null