博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
|洛谷|二分|P1182 数列分段Section II
阅读量:4581 次
发布时间:2019-06-09

本文共 609 字,大约阅读时间需要 2 分钟。

http://www.luogu.org/problem/show?pid=1182

用二分答案,check即可

#include
#include
#include
#include
#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

转载于:https://www.cnblogs.com/flyinthesky1/p/6384275.html

你可能感兴趣的文章
SQL Server 语法大全
查看>>
MySQL存储过程
查看>>
HttpContext是干什么的
查看>>
线程安全
查看>>
原形模式
查看>>
iOS开发笔记5:多线程之NSThread、NSOperation及GCD
查看>>
php中curl的详细解说【转】
查看>>
Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
查看>>
hdu 6069 Counting Divisors 筛法
查看>>
codeforces gym 100971 K Palindromization 思路
查看>>
各个控件说明
查看>>
鼠标事件(jQuery)
查看>>
delete指针时coredump的分析之旅
查看>>
openoffice+pdf2swf+FlexPaper在线显示office和pdf
查看>>
24-React Components组件
查看>>
[BZOJ 1188] [HNOI2007] 分裂游戏 【博弈论|SG函数】
查看>>
[BZOJ - 2631] tree 【LCT】
查看>>
ASP.NET Core管道深度剖析(2):创建一个“迷你版”的管道来模拟真实管道请求处理流程...
查看>>
JS实现数组排序:升序和降序
查看>>
怎样写具体设计文档
查看>>