|洛谷|二分|P1182 数列分段Section II
来源:互联网 发布:linux常用命令实例详解 编辑:程序博客网 时间:2024/05/22 11:57
http://www.luogu.org/problem/show?pid=1182
用二分答案,check即可
#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#define ms(i,j) memset(i,j, sizeof i);using namespace std;int n,m;int a[100005];bool check(int x)//大于m return 1;{int ans = 1;int tot = 0;for (int i=1;i<=n;i++){if (tot+a[i]<=x) tot+=a[i];else {ans++; tot = a[i];}}if (ans>m) return 1;else return 0;}int main(){scanf("%d%d", &n ,&m);int l = 0,r = 0;for (int i=1;i<=n;i++) {scanf("%d", &a[i]); r+=a[i]; l = max(l, a[i]);}while (l<r){int mid = (l+r)/2;if (check(mid)) l = mid+1;else r = mid;}printf("%d\n", l); return 0;}
0 0
- |洛谷|二分|P1182 数列分段Section II
- 洛谷P1182 数列分段Section II(二分)
- 洛谷 P1182数列分段Section II
- 洛谷 P1182 数列分段Section II
- 洛谷 P1182 数列分段Section II
- 【分治】洛谷 P1182 数列分段Section II
- P1182 数列分段Section II
- 水——洛谷P1182 数列分段Section II
- luogu P1182 数列分段Section II
- 洛谷 [P1182] 数列分段
- 洛谷Oj-数列分段Section II-贪心 + 二分答案
- 洛谷1182 数列分段Section II
- |洛谷|模拟|P1181 数列分段Section I
- 洛谷1181数列分段Section I
- 洛谷 P1181 数列分段Section I
- 洛谷 P1181 数列分段Section I
- 洛谷 P1181 数列分段Section I
- 【模拟】洛谷 P1181 数列分段Section I
- 【JAVA数据结构】双向链表
- 欧拉路径/欧拉回路
- HQL的使用及封装的操作数据的工具类
- Windows7 下 theano + keras + cuda 机器学习环境搭建
- Android_5.0定制--------keyCode实现SystemUI导航栏音量+ - 按钮
- |洛谷|二分|P1182 数列分段Section II
- 二叉树先序、中序、后续遍历递归以及非递归java实现
- 龙虎山:免费上WIFI,江西首个全面铺设免费无线上网的景区
- Opencv Surf算子中keyPoints,描述子Mat矩阵,配对向量DMatch里都包含了哪些好玩的东东?
- codeforces 665F. Four Divisors(求n以内因子数是4的数的个数)
- UVa 455 周期串
- java对象的内存分配编辑与寄存器 、堆栈、堆、静态存储等
- evaluate-reverse-polish-notation(逆波兰表示求值)
- Opencv模块功能介绍