[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个数的数列拆成若干段,保证每一段的前缀和都非负,求最多能拆成多少段. 题目 ...
随机推荐
- php 下载保存文件保存到本地的两种方法
第一种: 1 <? ?> 或 <?php //下载文件保存到本地//www.jbxue.comfunction downfile($fileurl){ob_start(); $fil ...
- SSAS维度上有多个表的注意事项
在Sql Server Analysis Service中维度上有多张表(大于一张表)时,一定要注意将第二张表开始用到维度属性中的KeyColumns下的NullProcessing要设置为Unkno ...
- Mongodb 笔记06 副本集的组成、从应用程序连接副本集、管理
副本集的组成 1. 同步:MongoDB的复制功能是使用操作日志oplog实现的,操作日志包含了主节点的每一次写操作.oplog是主节点的local数据库中的一个固定集合.备份节点通过查询整个集合就可 ...
- pycharm常用快捷键
Alt+Enter 自动添加包Ctrl+t SVN更新Ctrl+k SVN提交Ctrl + / 注释(取消注释)选择的行Ctrl+Shift+F 高级查找Ctrl+Enter 补全Shift + En ...
- gerrit docker运行失败 chown: /var/gerrit/review_site: Permission denied 【已解决】
Docker Volume 之权限管理(转) - jackluo - 博客园 http://www.cnblogs.com/jackluo/p/5783116.html 为什么在公司电脑没有问题,但在 ...
- sqlserver常用调优脚本(转)
(转)以备不时之需 最耗时的sql declare @n int set @n=500 ; with cte1 as(select a.*,t.*from sys.dm_exec_query_stat ...
- 【python cookbook】【数据结构与算法】5.实现优先级队列
问题:要实现一个队列,它能够以给定的优先级对元素排序,且每次pop操作时都会返回优先级最高的那个元素: 解决方案:采用heapq模块实现一个简单的优先级队列 # example.py # # Exam ...
- 161201、常用 SQL Server 规范集锦
常见的字段类型选择 1.字符类型建议采用varchar/nvarchar数据类型 2.金额货币建议采用money数据类型 3.科学计数建议采用numeric数据类型 4.自增长标识建议采用bigi ...
- rsync的断点续传设置。
关于rsync的断点续传 关于rsync的断点续传 经常copy大文件,由于服务器.路由等网络的不确定性,老是出现 remote server not responding.于是查了下资料,发现rsy ...
- NIOS II开发备忘录
大概有一年没做NIOS II的开发了,回想上一次做NIOS II还是去年做毕业设计的时候.那时候做的是基于SOPC的频率特性测试仪,我大约花了2个月的时间,从无到有的学习了NIOS II开发.学习过N ...