HDU
来源:互联网 发布:mac chrome 常用插件 编辑:程序博客网 时间:2024/06/11 11:44
保证有解的情况下,对于每一个负数,前面都存在几个正数使之前缀和大于零
从后往前找一遍,遇到负数往前加
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <set>#include <queue>#include <algorithm>#include <vector>#include <cctype>#include <stack>#include <sstream>#include <list>#include <map>#include <assert.h>#define debug() puts("************")#define MS(a,b) memset(a,b,sizeof a)using namespace std;typedef long long ll;typedef pair<int,int> P;const int INF = 0x3f3f3f3f;const double inf = 1e20;const double eps = 1e-15;const int dx[] = {-1,0,1,0};const int dy[] = {0,1,0,-1};const int maxn = 1000000 + 7, maxd = 100000 + 7;int n;ll a[maxn];int main() { while(scanf("%d", &n) != EOF && n) { for(int i = 0; i < n; ++i) scanf("%lld", &a[i]); int ans = 0; for(int i = n-1; i >= 0; --i) { if(a[i] >= 0) ans++; else a[i-1] += a[i]; } printf("%d\n", ans); } return 0;}
阅读全文
1 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- HDU
- 安卓学习-activity
- hdu 6161--Big binary tree(思维--压缩空间)
- Math,Arrays,Random常用方法总结
- 对称加密算法(4):PEB
- HDU
- JAVA NIO
- 中企动力“外贸门户”助力中小企业揽胜“一带一路”
- 从零开始的"E"世界(J2SE)
- Linux CentOS设置静态获取ip,解决无法上网问题
- 1031:求车速
- 掌握业务流程图符号,提高业绩不再没有头绪
- 【九度OJ】1179:阶乘
- Spark学习笔记一:环境配置及数据准备