HDU 5783 Divide the Sequence——贪心
来源:互联网 发布:chrome js 拷贝 编辑:程序博客网 时间:2024/05/25 23:25
这道题关键要理解题意:每个子串的【所有前缀和】都大于等于0,比如1 1 -2,满足1>=0, 1 + 1>=0, 1 + 1 + -2 >= 0
明白这一点后,就能很自然的想出倒着扫的策略
最后注意用long long
#include <cstdio>using namespace std;typedef long long ll;const int MAXN = 1e6 + 10;int T, N;ll a[MAXN];int main() { while (~scanf("%d", &N)) { for (int i = 1; i <= N; i++) scanf("%I64d", &a[i]); int ans = 0; for (int i = N; i >= 1; i--) { if (a[i] >= 0) ans++; else { a[i - 1] += a[i]; } } printf("%d\n", ans); } return 0;}
阅读全文
0 0
- HDU 5783 Divide the Sequence——贪心
- HDU 5783 Divide the Sequence 【贪心】
- HDU 5783 Divide the Sequence(贪心)
- 【贪心】HDU 5783 Divide the Sequence
- hdu 5783——Divide the Sequence
- HDU-5783 Divide the Sequence(贪心水题)
- 2016多校5 hdu 5783 Divide the Sequence 贪心
- hdu 5783 Divide the Sequence
- Divide the Sequence hdu 5783
- hdu 5783 Divide the Sequence
- HDU 5783 Divide the Sequence
- 【HDU】5783 Divide the Sequence
- hdu 5783 Divide the Sequence
- HDU 5783 Divide the Sequence
- HDU 5783 Divide the Sequence
- HDOJ 5783 Divide the Sequence(贪心)
- HDU5783 Divide the Sequence(贪心)
- hdu 5783 Divide the Sequence【水题】
- python decorator
- Object-C的编译命令
- Nginx编译安装
- hdfs——hadoop文件读写操作
- 在共享内存实现 Redis(上)
- HDU 5783 Divide the Sequence——贪心
- shiro中的请求参数
- android UiAutomator生成测试报告的基本方法封装
- BZOJ4538 网络 [树链剖分]
- Powershell原生支持的cURL
- java基础——java api各包概述
- windows重启系统
- systemd详解
- POJ4081树的转换以及deque iterator not dereferencable 问题