[HDOJ5783]Divide the Sequence(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783
题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0。
从后往前截取,这样不会影响到未截取的部分。维护当前的前缀和,每次截取不要忘记给前缀和置零。
#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int maxn = ;
int n, ret;
LL cur;
LL a[maxn]; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d", &n)) {
ret = ;
for(int i = ; i <= n; i++) {
scanf("%I64d", &a[i]);
}
int i = n; cur = ;
while(i >= ) {
cur += a[i];
if(cur >= ) {
cur = ;
ret++;
}
i--;
}
printf("%d\n", ret);
}
return ;
}
[HDOJ5783]Divide the Sequence(贪心)的更多相关文章
- hdu 5783 Divide the Sequence 贪心
Divide the Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...
- Divide the Sequence (贪心)
题意:求将一串数据尽可能多分成所有前缀和大于0的连续子串. 思路:由于是要求所有前缀和大于0,那么只要从后往前推就好了. #include<bits/stdc++.h> using nam ...
- HDU 5783 Divide the Sequence (贪心)
Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a seq ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5783 Divide the Sequence
Divide the Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 2016 Multi-University Training Contest 5 Divide the Sequence
Divide the Sequence 题意: 给你一个序列A,问你最多能够分成多少个连续子序列,使得每个子序列的所有前缀和均不小于0 题解: 这题是比赛时候的水题,但我比的时候也就做出这一题, = ...
- HDU5014Number Sequence(贪心)
HDU5014Number Sequence(贪心) 题目链接 题目大意: 给出n,然后给出一个数字串,长度为n + 1, 范围在[0, n - 1].然后要求你找出另外一个序列B,满足上述的要求,而 ...
- 【题解】Cut the Sequence(贪心区间覆盖)
[题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ...
- 【贪心】HDU 5783 Divide the Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 题目大意: 把一个N个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...
随机推荐
- SQL Server数据库的三种恢复模式:简单恢复模式、完整恢复模式和大容量日志恢复模式(转载)
SQL Server数据库有三种恢复模式:简单恢复模式.完整恢复模式和大容量日志恢复模式: 1.Simple 简单恢复模式, Simple模式的旧称叫”Checkpoint with truncate ...
- 菜鸟,大牛和教主三者的区别(转自hzwer)
菜鸟,大牛和教主,三者的区别 对菜鸟来说题目有三种:会算法且能AC的,会算法但不能AC的,不会做的 对大牛来说题目有两种:会做的,不会做的 对教主来说题目有两种:能AC的,数据有错的 菜鸟提交WA了, ...
- Openstack的dashboard开发之【浏览器兼容性】
完全不支持浏览器: ie9(含)以下ie低版本浏览器及使用ie低版本浏览器的内核的扩展浏览器,如360安全浏览器(内核ie6) 原因:不支持vnc(需要浏览器支持才有vnc功能),jquery也不在支 ...
- 通过进程检测服务时脚本文件名不要起要检测的服务名字命名 shell程序从上到下执行若定义函数或引用系统函数需先定义 kill -USR2
通过进程检测服务时脚本文件名不要起要检测的服务名字命名 kill -USR2 `cat /var/run/mysqld.pid`
- eclipse Juno Indigo Helios Galileo这几种版本的意思
Eclipse 3.1 版本代号 IO [木卫1,伊奥] Eclipse 3.2, 30-06-2006, Callisto projects, 版本代号 Callisto [木卫四,卡里斯托 ] ...
- javaWeb request乱码处理
//解决get方式提交的乱码 String name = request.getParameter("name"); name=new String(u ...
- matlab读入矩阵数据
方法: 很简单,把矩阵数据存到excel里,然后存成cvs的格式,就是把每行数据之间用‘,’分隔:行与行之间用‘\n’保存. 举例: 假设cvs为test_nnfeature.txt,后缀可以改啦,只 ...
- VirtualBox启动虚拟机报错0x80004005
Unable to load R3 module C:\Program Files\Oracle\VirtualBox/VBoxDD.DLL (VBoxDD): GetLastError=1790 ( ...
- quick lua 使用spine骨骼动画
看下下面两个文件 <spine/SkeletonRenderer.h><spine/SkeletonAnimation.h> 1.lua中创建方法: sp.SkeletonAn ...
- ZOJ 3866 - Cylinder Candy
3866 - Cylinder Candy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...